如何用Net::SMTP实现自动发送Email?

如何用Net::SMTP实现自动发送Email?

如何用Net::SMTP实现自动发送Email?
use Net::SMTP;

my $mailhost = "smtp.163.com"; #The smtp host
my $mailfrom = 'Chennysky@163.com'; #Send email address
my @mailto = ('Chenny.chen@fangtek.com.cn', 'chennysky@sohu.com'); #The recipient list
my $subject = "此为标题";
my $text = "此为正文\n第二行位于此。";

$smtp = Net::SMTP->new($mailhost, Hello => '163.com', Timeout => 180, Debug => 1)
||die 'Cannot connect to server \'$mailhost\'';
#$smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120, Debug => 1);

# anth login, type your user name and password here
$smtp->auth($mailfrom,'pswd');

foreach my $mailto (@mailto) {
# Send the From and Recipient for the mail servers that require it
$smtp->mail($mailfrom);
$smtp->to($mailto);

# Start the mail
$smtp->data();

# Send the header
$smtp->datasend("To: $mailto\n");
$smtp->datasend("From: $mailfrom\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");

# Send the message
$smtp->datasend("$text\n\n");

# Send the termination string
$smtp->dataend();
}
$smtp->quit;

我这个小程序调试了2天还是不能正常运行呢,总提示我用户错,可是我从163网址进入邮箱都是正确的用户名和密码呀

Net::SMTP=GLOB(0x19e2604)<<< 553 You are not authorized to send mail as <MAIL FROM:<Chennysky@163.com>>, authentication is required
Net::SMTP=GLOB(0x19e2604)>>> RCPT TO:<Chenny.chen@fangtek.com.cn>

请各位帮忙看看是怎么回事?
authentication is required
you need to give username(mail address) and password before you can send mail as the one you declared to be.
$smtp->auth($mailfrom.
$smtp->auth($mailfrom,'pswd');

不是 $mailfrom 是 @163.com 前面的东西
NET::SMTP发信(认证)代码,以前有写过的
#!/usr/bin/perl
#名称:MOD_PERL SMTP发信(认证)程序
#类型:OpenSource
#原作者:邱雄盛
#开发时间:2003-5-8 17:10

use Net::SMTP;
use MIME::Base64;
print "Content-type: text/plain\n\n";

my $ServerName = "127.0.0.1";
my $mailfrom = "webmaster\@127.0.0.1";
my $smtpuser = "webmaster";
my $smtppass = "administrator";
my $mailto = "webmaster\@127.0.0.1";
my $subject = "Test Message Title";

$smtp = Net::SMTP->new($ServerName, Timeout => 60);
if(!$smtp){print "Soryy,mail server was off!\n";exit;}

my $encode_smtpuser = encode_base64($smtpuser);
my $encode_smtppass = encode_base64($smtppass);

$smtp->mail($mailfrom);
$smtp->to($mailto);

my $result = $smtp->command('AUTH','LOGIN');
my $answer = $smtp->getline();
# 334 VXNlcm5hbWU6
$result = $smtp->command($encode_smtpuser);
$answer = $smtp->getline();
# 334 UGFzc3dvcmQ6
$result = $smtp->command($encode_smtppass);
$answer = $smtp->getline();
# 235 Authentication successful or 535 Authentication failed
if ($answer =~ /535/i){print "Soryy,mail server is error!\n";exit;}
$smtp->data();
$smtp->datasend("To: $mailto\n");
$smtp->datasend("From: $mailfrom\n");
$smtp->datasend("Reply-to: $replyaddr\n") if ($replyaddr ne "");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("X-Mailer: FJPC.net Sendmail Mail Sender\n");
$smtp->datasend("Content-Type: text/html; charset=gb2312\n\n");

$smtp->datasend("Hello World!<br><a href=http://bbs.fjpc.net>http://bbs.fjpc.net</a>\n");
$smtp->dataend();

$smtp->quit();
print "0k";
exit;