perl发邮件脚本

1555阅读 0评论2008-11-28 zlj2208
分类:PERL

perl发邮件脚本

作者:zlj2208

修改日期:2008年11月28日

转载请注明转自http://zlj2208.cublog.cn/



使用perl发送邮件脚本

在*nix下面使用sendmail -t

#cat send_mail.pl

#!/usr/bin/perl -w
#Author:Zhou Lijun
#Date  :2008-09-03

#perl -MCPAN -e shell
#cpan>install Net::SMTP_auth
use Net::SMTP;
use Net::SMTP_auth;
use MIME::Base64;
$mail_server = 'smtp.domain.com';
$mail_from = 'user1@domain.com';
$mail_to = 'user2@domain.com';
$uname='username';
$password='password';

###不通过smtp认证发送邮件
##开启Debug模式
#$smtp = Net::SMTP->new("$mail_server" , Debug => 1);
##普通发送模式
#$smtp = Net::SMTP->new("$mail_server" );
#$smtp->auth("$uname", "$password");

###通过smtp认证发送邮件
##开启Debug模式
$smtp = Net::SMTP_auth->new("$mail_server" , Debug => 1);
##普通发送模式
#$smtp = Net::SMTP_auth->new("$mail_server" );
$smtp->auth("login", "$uname", "$password");

$smtp->mail("$mail_from");
$smtp->to("$mail_to");
$smtp->data();
$smtp->datasend("from:$mail_from");
$smtp->datasend("To:$mail_to");
$smtp->datasend("Reply-To:$mail_from");
$smtp->datasend("Return-Path:$mail_from");
$smtp->datasend('Subject:Your Subject');
$smtp->datasend('Content-Type:text/plain; ChartSet=gb2312');
$smtp->datasend('Your mail content!');
$smtp->datasend('\n');
$smtp->quit;
上一篇:Dynagen 2621XM配置模板
下一篇:cacti安装说明