Chinaunix首页 | 论坛 | 博客
  • 博客访问: 952321
  • 博文数量: 99
  • 博客积分: 3306
  • 博客等级: 中校
  • 技术积分: 1238
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-21 10:14
文章分类

全部博文(99)

文章存档

2012年(37)

2011年(56)

2010年(6)

分类: 系统运维

2011-08-18 10:09:26

如果是登陆到远程smtp服务器上发送的话可以使用

  1. #!/usr/bin/perl -w
  2. use Mail::Sender;
  3. use strict;
  4. printf("please input your passwd:\n");
  5. system "stty -echo";
  6. my $pass;
  7. chomp($pass=<STDIN>);
  8. system "stty echo";
  9. my $sender= new Mail::Sender{
  10.     smtp=> 'smtp.126.com',
  11.     from=>'user@126.com',
  12.     auth=>'LOGIN',
  13.     authid=>'user',
  14.     authpwd=> $pass,
  15.     debug=>'./perllog'
  16. };
  17. $sender->MailMsg({
  18.     to=>'user2@126.com',
  19.     subject=>'perl send mail',
  20.     msg=>'中文测试',
  21.     debug=>'./perllog'
  22. }) or die "failed";
  23. $sender->Close();
  24. 再提供一个可以发送附件的版本,直接使用内部的邮件服务器发送一些小文件。如果想使用远程服务器可以根据前面的脚本修改。
  25. #!/usr/bin/perl -w
  26. use Mail::Sender;
  27. my $txt;
  28. $txt="hi,all :\n\t xxxx!";
  29. &sendmsg($ARGV[0],$txt,$ARGV[1]);
  30. sub sendmsg()
  31. {
  32.         my $add=$_[0]; #email address
  33.         my $msg="$_[1]"; #email txt
  34.         my $file=$_[2];#file
  35.         open my $LOG ,">/tmp/mail.log";
  36.         my $sender =new Mail::Sender 
  37.                 {
  38.             
  39.                 smtp=>'your smtp server host',
  40.                 from=>'xxx@xxx.com',
  41.                 debug=>'./perllog'
  42.                 }  or die "new sender failed.";

  43.         $sender->MailFile(
  44.         {
  45.                 to=>$add,
  46.                 subject=>"hello",
  47.                 msg=>"$msg",
  48.                 debug=>$LOG,
  49.                 file => $file,
  50.                 charset => 'gb2312'
  51.         }
  52.         ) or die "$Mail::Sender::Error\n";
  53.         close($LOG);
  54.         $sender->Close;
  55. }
阅读(4064) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~