1, 在不需要认证的smtp服务器上发送邮件
#!/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: 测试主题\n"); #主题
$smtp->datasend("\n");
$smtp->datasend("A simple test message 测试中英文混合\n"); #消息内容
$smtp->dataend();
$smtp->quit;
2, 在需要认证的smtp服务器上发送邮件
#!/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;
阅读(6970) | 评论(0) | 转发(1) |