Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1163547
  • 博文数量: 146
  • 博客积分: 6619
  • 博客等级: 准将
  • 技术积分: 1621
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-29 14:06
文章分类

全部博文(146)

文章存档

2020年(1)

2019年(4)

2018年(3)

2017年(5)

2015年(5)

2014年(7)

2013年(5)

2012年(11)

2011年(15)

2010年(13)

2009年(14)

2008年(63)

分类: Python/Ruby

2012-01-31 14:58:20

收藏一下自己的帖子。
-------------------------------------------------------------------------------
我用以下代码发邮件,出现奇怪错误,以前都是正常的,麻烦各位帮忙看看,谢谢!
#!/usr/bin/perl

use Net::SMTP;

my $mailhost = "smtp.163.com"; # the smtp host

my $mailfrom = [email=]'from@163.com'[/email]; # your email address

my @mailto = ([email=]'to@qq.com'[/email]); # the recipient list

my $subject = "此为标题";
my $text = "此为正文\n第二行位于此。";

my $smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120, Debug => 1);

# anth login, type your user name and password here

$smtp->auth('user','pass'); #用户名和密码确定没错

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;

DEBUG出来结果如下:

Net::SMTP>>> Net::SMTP(2.31)
Net::SMTP>>>   Net::Cmd(2.29)
Net::SMTP>>>     Exporter(5.62)
Net::SMTP>>>   IO::Socket::INET(1.31)
Net::SMTP>>>     IO::Socket(1.30_01)
Net::SMTP>>>       IO::Handle(1.27)
Net::SMTP=GLOB(0x183631c)<<< 220 163.com Anti-spam GT for Coremail System (163co
m[20081010])
Net::SMTP=GLOB(0x183631c)>>> EHLO localhost
Net::SMTP=GLOB(0x183631c)<<< 250-mail
Net::SMTP=GLOB(0x183631c)<<< 250-PIPELINING
Net::SMTP=GLOB(0x183631c)<<< 250-AUTH LOGIN PLAIN
Net::SMTP=GLOB(0x183631c)<<< 250-AUTH=LOGIN PLAIN
Net::SMTP=GLOB(0x183631c)<<< 250 8BITMIME
Net::SMTP=GLOB(0x183631c)>>> MAIL FROM:<>
Net::SMTP=GLOB(0x183631c)<<< 553 authentication is required,smtp10,DsCowLCLvwBqt
0VKfc3kKw--.28997S2 1246082922
Net::SMTP=GLOB(0x183631c)>>> RCPT TO:<>
Net::SMTP=GLOB(0x183631c)<<< 503 bad sequence of commands
Net::SMTP=GLOB(0x183631c)>>> DATA
Net::SMTP=GLOB(0x183631c)<<< 503 bad sequence of commands
Net::SMTP=GLOB(0x183631c)>>> To:
Net::SMTP=GLOB(0x183631c)>>> From: example
Net::SMTP=GLOB(0x183631c)>>> Subject: 此为标题
Net::SMTP=GLOB(0x183631c)>>> 此为正文
Net::SMTP=GLOB(0x183631c)>>> 第二行位于此。
Net::SMTP=GLOB(0x183631c)>>> .
Net::SMTP=GLOB(0x183631c)<<< 502 Error: command not implemented
Net::SMTP=GLOB(0x183631c)>>> QUIT
Net::SMTP=GLOB(0x183631c)<<< 502 Error: command not implemented

 

 

解决方案:安装一下 Authen::SASL模块

阅读(4360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~