我写了一个perl脚本使用Gmail的SMTP服务器发送电子邮件:smtp.gmail.com -
use Net::SMTP;
my $smtp = Net::SMTP->new('smtp.gmail.com',
Port=> 587,
Timeout => 20,
Hello=>'user@gmail.com'
);
print $smtp->domain,"\n";
$sender = "user@gmail.com";
$password = "mypassword";
$smtp->auth ( $sender, $password ) or die "could not authenticate\n";
$receiver = "user@gmail.com";
$subject = "my custom subject";
$smtp->mail($sender);
$smtp->to($receiver);
$smtp->data();
$smtp->datasend("To: <$reciever> \n");
$smtp->datasend("From: <$sender> \n");
$smtp->datasend("Content-Type: text/html \n");
$smtp->datasend("Subject: $subject");
$smtp->datasend("\n");
$smtp->datasend('the body of the email');
$smtp->dataend();
$smtp->quit();
print "done\n\n";
对于“用户”,我有我的Gmail用户名和“输入mypassword”我有密码。 但是,当我运行此代码它停止在自己给AUTH:无法验证。
我能够连接到谷歌的SMTP serever我得到:“mx.google.com”作为的结果:
打印$ SMTP的>域名, “\ n”;
它是什么,我做错了什么? 请帮忙。