+ -
当前位置:首页 → 问答吧 → 关于Perl处理邮件通知的问题

关于Perl处理邮件通知的问题

时间:2010-10-12

来源:互联网

最近有个这个需求,想在本地(使用的系统是CentOS) 给邮件服务器(Windows 2003 Server Mail Server )
发送测试邮件。


请问该如何实现此功能呢? 谢谢

作者: jiannma   发布时间: 2010-10-12

我正在做一个关于检测垃圾邮件的东东 我表示 我恨死邮件了

作者: 猪鼻插葱   发布时间: 2010-10-12

不知道你想具体测什么
不过这个是我以前写过的一个,看看有没有什么帮助
  1. use Mail::Sender;

  2. sub sendmail(){
  3.     my $addressee = shift @_;
  4.     my $cc = shift @_;
  5.     my $subject = shift @_;   
  6.     my @body = @_;
  7.     eval{
  8.         my $sender = new Mail::Sender {
  9.                        smtp => 'mail.XXX.com.cn',   #这里写邮件服务器地址
  10.                        from => '[email protected]',    #发件人地址
  11.                        to => $addressee,            #收件人地址
  12.                        cc => $cc,                   #抄送人地址
  13.                        on_errors => 'die',
  14.                };
  15.         $sender->Open({
  16.                subject => $subject,       #标题
  17.                ctype => "text/html",
  18.                encoding => "GB2312"
  19.         }) or die $Mail::Sender::Error,"\n";
  20.         for (@body) { $sender->SendEx($_) };
  21.         $sender->Close();
  22.     };
  23.     print $@;
  24.     if($@){
  25.         return 0;
  26.     }else{
  27.         return 1;
  28.     }
  29. }
复制代码

作者: 珞水的大叔   发布时间: 2010-10-12

回复 珞水的大叔


    谢谢 刚我自己查了下资料 ,发现还可以使用perl里面的Net::SMTP模块解决  

具体代码如下:
  1. #!/usr/bin/perl

  2. use Net::SMTP;



  3.         $smtp = Net::SMTP->new('mail.test.com'); # connect to an SMTP server

  4.         $smtp->mail( '[email protected]' );     # use the sender's address here

  5.         $smtp->to('[email protected]');        # recipient's address

  6.         $smtp->data();                      # Start the mail



  7.         # Send the header.

  8.         $smtp->datasend("To: [email protected]\n");

  9.         $smtp->datasend("From: [email protected]\n");

  10.         $smtp->datasend("\n");



  11.         # Send the body.

  12.         $smtp->datasend("Hello, World!\n");

  13.         $smtp->dataend();                   # Finish sending the mail

  14.         $smtp->quit;                        # Close the SMTP connection

复制代码

作者: jiannma   发布时间: 2010-10-12

回复 jiannma


    呵呵,那加油啦
   邮件处理确实很麻烦……

作者: 珞水的大叔   发布时间: 2010-10-12

大叔 我问你个问题 我知道CPAN是个很好用的东西 但是我不知道怎么寻找能够实现自己想要的功能的具体模块 怎么才能快速的找到呢?

作者: 猪鼻插葱   发布时间: 2010-10-12