Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2542901
  • 博文数量: 271
  • 博客积分: 6659
  • 博客等级: 准将
  • 技术积分: 3141
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-17 10:24
文章分类

全部博文(271)

文章存档

2016年(2)

2015年(12)

2014年(7)

2013年(19)

2012年(22)

2011年(81)

2010年(128)

分类: Python/Ruby

2011-01-10 13:44:18

#!/usr/bin/perl
use Net::SMTP;

my $mailhost = "smtp.126.com"; # the smtp host
my $mailfrom = 'xxx@126.com'; # your email address
my @mailto = ('xxxx@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('126user','126password');

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,一般测试一次完毕,正式使用的话会关闭它。


阅读(1594) | 评论(1) | 转发(0) |
0

上一篇:perl 磁盘检测.pl

下一篇:ascii

给主人留下些什么吧!~~

chinaunix网友2011-03-09 13:34:19

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com