用Perl 的NET::SMTP 发送电子邮件始终报错:Auth Error! No such file or directory
经分析是因为 Authen::SASL Module 没有装。
sudo cpanm Authen::SASL
就可以正常使用。
附 send_mail.pl:
#!/usr/bin/perl -w
use Net::SMTP;
my $to_address = 'xxxx@163.com';
my $mail_user = 'xx@163.com';
my $mail_pwd = 'xxxxx';
my $mail_server = 'smtp.163.com';
my $from = "From: 测试<xxxx\@163.com>\n";
my $subject = "Subject: 测试\n\n";
my $message = <<CONTENT;
**********************
here comes the content
**********************
CONTENT
my $smtp = Net::SMTP->new($mail_server);
$smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
$smtp->mail($mail_user);
$smtp->to($to_address);
$smtp->data(); # begin the data
$smtp->datasend($from); # set user
$smtp->datasend("To: Hello<hello\@163.com>\n");
$smtp->datasend("Content-Type: text/html; charset=utf-8\n");
$smtp->datasend($subject); # set subject
$smtp->datasend($message); # set content
$smtp->dataend();
$smtp->quit();