作者u9423504 (波哥)
看板Perl
标题[问题] Net::SMTP::SSL 模组寄信的问题
时间Thu May 6 18:20:57 2010
小弟最近使用Perl 的Net::SMTP::SSL模组 写寄信的程式,
主要的目的是要在命令列模式下透过gmail server 把信给寄出去。
程式码可以正常执行无任何错误讯息跑出。 但是,信箱就是没有
收到寄过来的信,不晓得原因是发生在那里?!
程式码如下:
#!/usr/bin/perl
use warnings;
use strict;
use Net::SMTP::SSL;
my $user = '
[email protected]';
my $pass = 'n123';
my $server = 'smtp.googlemail.com';
my $to = '
[email protected]';
my $from_name = 'james';
my $from_email = '
[email protected]';
my $subject = 'smtp-ssl-auth test';
my $smtps = Net::SMTP::SSL->new($server,
Port => 465,
DEBUG => 1,
) or warn "$!\n";
# I just lucked out and this worked for auth (yeah inheritance :-) )
defined ($smtps->auth($user, $pass))
or die "Can't authenticate: $!\n";
$smtps->mail($from_email);
$smtps->to($to);
$smtps->data();
$smtps->datasend("To: $to\n");
$smtps->datasend(qq^From: "$from_name" <$from_email>\n^);
$smtps->datasend("Subject: $subject\n\n");
$smtps->datasend("This will be the body of the message.\n");
$smtps->datasend("\n--\nVery Official Looking .sig here\n");
$smtps->dataend();
$smtps->quit();
print "done\n";
--
波哥IT私房菜:
http://i-pogo.blogspot.com/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.117.126.25
※ 编辑: u9423504 来自: 122.117.126.25 (05/06 18:22)
※ 编辑: u9423504 来自: 122.117.126.25 (05/06 18:26)