[PerlChina] 答复: 答复: send mail in windows VISTA

Bruce Cheng bruce1914 at gmail.com
Wed Feb 13 05:13:50 PST 2008


好的, 谢谢!

 

发件人: china-pm-bounces+bruce1914=gmail.com at pm.org
[mailto:china-pm-bounces+bruce1914=gmail.com at pm.org] 代表 Prince Brave
发送时间: 2008年2月13日 21:10
收件人: china-pm at pm.org
主题: Re: [PerlChina] 答复: send mail in windows VISTA

 

首先需要指出的是: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/8155508a/attachment.html 


More information about the China-pm mailing list