1, send mail on an SMTP server that does not require authentication
#!/usr/bin/perl-w
Use NET::SMTP;
$SMTP = net::smtp->new ($mail _server); #邮件服务器地址
$smtp->mail ($send _user); #发件人
$smtp->to ($recv _user); #收件人
$SMTP->data ();
$smtp->datasend ("Subject: Test subject/n"); #主题
$SMTP->datasend ("n");
$smtp->datasend ("A Simple test message tests in English mix/n"); #消息内容
$SMTP->dataend ();
$SMTP->quit;
2, send mail on an SMTP server that requires authentication
#!/usr/bin/perl-w
Use strict;
Use Net::smtp_auth;
My $mailhost = ' mail.abc.cn ';
My $mailfrom = ' 120@abc.cn ';
My @mailto = (' aaa@163.com ',
' bbb@163.com ');
My $user = ' 120@abc.cn ';
My $passwd = ' 123456 ';
My $subject = ' hello ';
#my $text
My $f _list = '/home/sysadmin/scp.log ';
Open (FILE, $f _list) or die "Can not open list file/n";
Undef $/;
my $text =;
My $smtp = Net::smtp_auth->new ($mailhost, timeout=>120, Debug => 1) or die "error./n";
$smtp->auth (' LOGIN ', $user, $passwd);
foreach my $mailto (@mailto) {
$SMTP->mail ($mailfrom);
$SMTP->to ($mailto);
$SMTP->data ();
$smtp->datasend ("to: $mailto/n");
$smtp->datasend ("From: $mailfrom/n");
$smtp->datasend ("Subject: $subject/n");
$SMTP->datasend ("n");
$smtp->datasend ("$text/n/n");
$SMTP->dataend ();
}
$SMTP->quit;