使用perl mail::sender发送邮件

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

  
#!/usr/bin/perl -w  
use Mail::Sender;  
use strict;  
printf("please input your passwd:\n");  
system "stty -echo";  
my $pass;  
chomp($pass=<STDIN>);  
system "stty echo";  
my $sender= new Mail::Sender{  
smtp=> smtp.126.com,  
from=>user@126.com,  
auth=>LOGIN,  
authid=>user,  
authpwd=> $pass,  
debug=>./perllog  
};  
$sender->MailMsg({  
to=>user2@126.com,  
subject=>perl send mail,  
msg=>中文测试,  
debug=>./perllog  
}) or die "failed";  
$sender->Close();  
再提供一个可以发送附件的版本直接使用内部的邮件服务器发送一些小文件如果想使用远程服务器可以根据前面的脚本修改  
#!/usr/bin/perl -w  
use Mail::Sender;  
my $txt;  
$txt="hi,all :\n\t xxxx!";  
&sendmsg($ARGV[0],$txt,$ARGV[1]);  
sub sendmsg()  
{  
my $add=$_[0]; #email address  
my $msg="$_[1]"; #email txt  
my $file=$_[2];#file  
open my $LOG ,">/tmp/mail.log";  
my $sender =new Mail::Sender  
{

smtp=>your smtp server host,  
from=>xxx@xxx.com,  
debug=>./perllog  
}  or die "new sender failed.";

$sender->MailFile(  
{  
to=>$add,  
subject=>"hello",  
msg=>"$msg",  
debug=>$LOG,  
file => $file,  
charset => gb2312  
}  
) or die "$Mail::Sender::Error\n";  
close($LOG);  
$sender->Close;  
}