怎么用Perl来发送邮件

liangbch 2012-06-15 02:15:54
如题,要求perl脚本能够工作在Windows和Linux.
...全文
374 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangbch 2012-06-21
  • 打赏
  • 举报
回复
等换一台电脑试一试。
薛定谔之死猫 2012-06-21
  • 打赏
  • 举报
回复
只干过ruby的,不过在用的过程中perl、python和ruby的库都大同小异,估计是相互参考着实现的吧~
bugs2k 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

use strict;
use warnings;

use Mail::Sender;

my $sender = new Mail::Sender
{smtp => 'smtp.163.com', from => 'xxx@163.com'};

my $result = $sender->MailMsg({smtp => 'smtp.163.com', #这个是你的邮件服……
[/Quote]

貌似这个不太科学
liuweichuan 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

我不会傻到一字不改的,我把from,to,authid and authpwd 都替换为真实有效的数据,但是这个代码仍然不能工作。
[/Quote]

邮箱服务器 的参数改了吗, smtp 那个
liuweichuan 2012-06-18
  • 打赏
  • 举报
回复
use strict;
use warnings;

use Mail::Sender;

my $sender = new Mail::Sender
{smtp => 'smtp.163.com', from => 'xxx@163.com'};

my $result = $sender->MailMsg({smtp => 'smtp.163.com', #这个是你的邮件服务器的主机名
from => 'xxx@163.com',
to => '222@qq.com',
header => '',
subject => "Just a test!Don't reply!",
msg => "This is a test!\nIf you receive this email, that will prove that my perl script works successfully",
auth => 'login',
authid => 'xxx@163.com',
authpwd => 'xxxxxxx' #邮箱密码
});

if ($result < 0)
{
die "error!";
}

$sender->Close();
print "Success!\n";


你按这个改下参数
liuweichuan 2012-06-18
  • 打赏
  • 举报
回复
mail::sender 是对的, lz把你的代码 贴出来
liangbch 2012-06-18
  • 打赏
  • 举报
回复
我不会傻到一字不改的,我把from,to,authid and authpwd 都替换为真实有效的数据,但是这个代码仍然不能工作。
bugs2k 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

不行呀,依然不能发信。
[/Quote]

邮箱密码是错的,当然不行了

liangbch 2012-06-18
  • 打赏
  • 举报
回复
不行呀,依然不能发信。
bugs2k 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 的回复:]

引用 15 楼 的回复:
:-),哎呀,麻烦版主把密码删了吧



改了两段代码,看看是不是已经没有了!
[/Quote]
谢谢!
fibbery 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 的回复:]
:-),哎呀,麻烦版主把密码删了吧
[/Quote]


改了两段代码,看看是不是已经没有了!

bugs2k 2012-06-18
  • 打赏
  • 举报
回复
:-),哎呀,麻烦版主把密码删了吧
liangbch 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]
Perl code

zhu@ubuntu:~/perl$ perl -d mail.pl

Loading DB routines from perl5db.pl version 1.33
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::……
[/Quote]

可以的。
bugs2k 2012-06-18
  • 打赏
  • 举报
回复
zhu@ubuntu:~/perl$ perl -d mail.pl

Loading DB routines from perl5db.pl version 1.33
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(mail.pl:8): my $sender = new Mail::Sender({ from => 'bugs2k@163.com',
main::(mail.pl:9): smtp => 'smtp.163.com',
main::(mail.pl:10): auth => 'LOGIN',
main::(mail.pl:11): authid => 'bugs2k@163.com',
main::(mail.pl:12): authpwd => 'xxxxxx'})
main::(mail.pl:13): or die $!;
DB<1> n
main::(mail.pl:15): $sender->Open({ to => 'liangbaoch@163.com',
main::(mail.pl:16): subject => 'Hello dear friend'})
main::(mail.pl:17): or die $!;
DB<1> x $sender
0 Mail::Sender=HASH(0x1a5f028)
'TLS_allowed' => 1
'auth' => 'LOGIN'
'authid' => 'bugs2k@163.com'
'authpwd' => 'xxx'
'boundary' => 'Message-Boundary-by-Mail-Sender-1340000744'
'client' => 'localhost'
'debug' => 0
'from' => 'bugs2k@163.com'
'fromaddr' => 'bugs2k@163.com'
'multipart' => 'mixed'
'port' => 25
'proto' => 6
'replyaddr' => undef
'smtp' => 'smtp.163.com'
'smtpaddr' => 'ql
'
DB<2>


你能 ping 通 smtp.163.com
liangbch 2012-06-18
  • 打赏
  • 举报
回复
使用3楼的代码,使用perl -d 跟踪代码的执行。当执行完$sender->Open后,检查$sender的值,发现。
'error_msg' => 'connect() failed: 句柄无效。'
你全部信息为,这里略去了'authpwd'字段,和client字段。

DB<1> x $sender
0 Mail::Sender=HASH(0x1559bb4)
'TLS_allowed' => 1
'_had_newline' => 1
'auth' => 'LOGIN'
'authid' => 'liangbaoch@163.com'

'boundary' => 'Message-Boundary-by-Mail-Sender-1340000274'
'debug' => 0
'error' => '-3'
'error_msg' => 'connect() failed: 句柄无效。'
'from' => 'liangbaoch@163.com'
'fromaddr' => 'liangbaoch@163.com'
'multipart' => 0
'port' => 25
'proto' => 6
'replyaddr' => undef
'smtp' => 'smtp.163.com'
'smtpaddr' => '{}2?
'subject' => 'Hello dear friend'
'to' => 'baocheng.liang@magnumsemi.com'
'to_list' => ARRAY(0x13c556c)
0 'baocheng.liang@magnumsemi.com'
liangbch 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]
引用 6 楼 的回复:

我不会傻到一字不改的,我把from,to,authid and authpwd 都替换为真实有效的数据,但是这个代码仍然不能工作。


邮箱服务器 的参数改了吗, smtp 那个
[/Quote]

没有,这个本来就是对的,163的邮箱的发送邮件服务器就是smtp.163.com
bugs2k 2012-06-16
  • 打赏
  • 举报
回复
#!/usr/bin/perl

use strict;
use warnings;

use Mail::Sender;

my $sender = new Mail::Sender({ from => 'bugs2k@163.com',
smtp => 'smtp.163.com',
auth => 'LOGIN',
authid => 'bugs2k@163.com',
authpwd => 'xxx'})
or die $!;

$sender->Open({to => 'bugs2k@163.com', subject => 'Hello dear friend'}) or die $!;
my $FH = $sender->GetHandle();
print $FH "How are you?\n\n";
$sender->Close;
liangbch 2012-06-15
  • 打赏
  • 举报
回复
不行呀?我设置参数 smtp=> "smtp.163.com", 我的163信箱的server, from参数也使用我的163信箱,运行这个程序,没有报错,可是不能收到信?各个参数要怎么设置才行,或者,我这端需要启动个什么服务吗?
bugs2k 2012-06-15
  • 打赏
  • 举报
回复
#! /usr/local/bin/perl -w

use Mail::Sender;

ref ($sender = new Mail::Sender { from => 'liaojl@liaojl.com',
smtp => 'smtp-shanghai', boundary => 'This-is-a-mail-boundary-435427'})
or die "Error($sender) : $Mail::Sender::Error\n";

$sender->OpenMultipart({to => 'liaojl@liaojl.com',
subject => 'Mail::Sender.pm - new module'});
$sender->Body;
$sender->SendEnc(<<'*END*');
Here is a new module Mail::Sender.
It provides an object based interface to sending SMTP mails.
It uses a direct socket connection, so it doesn't need any
additional program.

Enjoy, Jenda
*END*
$sender->Attach(
{description => 'Perl module Mail::Sender.pm',
ctype => 'application/x-zip-encoded',
encoding => 'Base64',
disposition => 'attachment; filename="Sender.zip"; type="ZIP archive"',
file => 'sender.zip'
});
$sender->Close;


http://www.liaojl.com/archives/2008/01/perl-mail-sender.html

37,741

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧