shaoqin 发表于 2017-5-18 10:53:19

perl smtp 发送邮件

  原文:http://blog.chinaunix.net/uid-21505614-id-289463.html
  


use Net::SMTP;
my $mailhost = "smtp.126.com"; # the smtp host
my $mailfrom = 'my@126.com'; # your email address
my @mailto = ('my@163.com'); # the recipient list
my $subject = "标题";
my $text = "正文\n第二行位于此。";
#$smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120, Debug => 1);
$smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120);
# anth login, type your user name and password here
$smtp->auth('my@126.com','my126');
foreach my $mailto (@mailto) {
# Send the From and Recipient for the mail servers that require it
$smtp->mail($mailfrom);
$smtp->to($mailto);
# Start the mail
$smtp->data();
# Send the header
$smtp->datasend("To: $mailto\n");
$smtp->datasend("From: $mailfrom\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
# Send the message
$smtp->datasend("$text\n\n");
# Send the termination string
$smtp->dataend();
}
$smtp->quit;
 ##########################  #所需安装模块
  #use Net::SMTP
  #Authen::SASL
  ##########################
  #$stmp->auth('user','pass');
  #大部分SMTP服务器为了防止 spam /垃圾邮件,就需要用户验证身份。
  #此方法需要另外安装模块:Authen::SASL, 此模块可能系统不自带
  ##########################
  #Debug => 1
  #此段代码用于测试之用,所以开启了Debug,一般测试一次完毕,正式使用的话会关闭它。
页: [1]
查看完整版本: perl smtp 发送邮件