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

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值