37,741
社区成员
发帖
与我相关
我的任务
分享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";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>
#!/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;#! /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;