分类: LINUX
2011-11-27 23:05:22
#!/usr/bin/perl
use Net::SMTP_auth;
use strict;
use MIME::Base64;
my $smtphost = 'xx.xx.com';
my $smtpuser = 'xxx';
my $smtpwd = 'xxx';
my $mailto= $ARGV[0];
my $subject = $ARGV[1];
my $message = $ARGV[2];
my $smtp = Net::SMTP_auth->new($smtphost, Timeout => 60, Debug => 0, Hello => 'xx.com') or die "Connect smtp server fail\n";
$smtp->auth('LOGIN', $smtpuser, $smtpwd);
$smtp->mail($smtpuser);
$smtp->to($mailto);
$smtp->data();
$smtp->datasend("To: $mailto\n");
$smtp->datasend("Content-Type:text/html;charset=utf-8\n");
$smtp->datasend("Content-Transfer-Encoding:base64\n");
$smtp->datasend("Subject:=?utf-8?B?".encode_base64($subject,'')."?=\n\n");
$smtp->datasend("\n");
$smtp->datasend(encode_base64($message,'')." \n");
$smtp->dataend();
$smtp->quit;
perl email.pl 收件人 主题 邮件内容(支持中文)