[PerlChina] 答复: send mail in windows VISTA

Prince Brave prinbra at gmail.com
Wed Feb 13 05:10:10 PST 2008


首先需要指出的是:gmail 所使用的端口不是默认的 SMTP 端口25, 而是端口465,
而且也不是普通的smtp连接,而是带ssl的smtp(有关信信息在gmail的帮助中的邮
件客户端设置可以看到)。
你可以在CPAN上搜索smtp ssl 等的模块。perl 核心模块中的Net::SMTP只支持
sasl验证。
另外一个问题是:在认证之前你应该给smtp服务器发送一个ELHO命令,即先$smtp->
hello(),然后才是$smtp-> auth();关于smtp协议的细节
你有时间的话可以看一下相关的rfc文档,可以在google搜索" smtp rfc ",这样
你会对邮件发送的细节有个清楚的认识。
Bruce Cheng 写道:
>
> 我的代码是这样写的:
>
> #! c:/perl/bin/perl.exe
>
> use Net::SMTP ;
>
> $smtp = Net::SMTP->new('smtp.gmail.com') or die "Error1 : $!\n" ;
>
> print $smtp->domain ;
>
> $smtp->auth('username', 'password') or die "Error2 : $!\n";
>
> $smtp->mail('bruce1914 at gmail.com') or die "Error3 : $!\n";
>
> $smtp->to('bruce1985cx at 163.com') or die "Error4 : $!\n";
>
> $smtp->data() ;
>
> print $smtp ;
>
> $smtp->datasend("To: bruce1985cx at 163.com\n") or die "Error5 : $!\n" ;
>
> $smtp->datasend("\n") ;
>
> $smtp->datasend("A simple test message\n") or die "Error 6: $!\n" ;
>
> $smtp->dataend() or die "Error7 : $!\n";
>
> $smtp->quit ;
>
> 运行结果:
>
> Error2 : No such file or directory
>
> mx.google.com
>
> 我试了很多网上别人提供的代码都不行,不知道哪儿有问题。
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20080213/21348e27/attachment-0001.html 


More information about the China-pm mailing list