Perl定制并发送邮件

  用了两天时间,现学了perl,主要用来发送一些自定义的邮件。注意:邮件正文为eicar,杀毒软件会提示病毒。请使用时将其替换。

简单代码如下:

 

#!/usr/bin/perl use Net::SMTP; sub GetCurTime(); $num=@ARGV; $counter=0; if($num != 1) { print "Usage: perl smtp.pl number/n"; print "number: the count of mails to send.Defaut is 1./n"; $ARGV[0]=1; } $smtp=Net::SMTP->new("10.226.70.32",Timeout=>60); if(!$smtp) { print "Connection is refused or times out.Please check the mail server or network connection/n"; exit 0; } #print "/$smtp=$smtp/n"; print "/nDomain:",$smtp->domain(),"/n"; print "Banner:",$smtp->banner(),"/n"; $from='[email protected]'; @to=('[email protected]','[email protected]'); $body='X5O!P%@AP[4/PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'; $lento=@to; print "sending.../n"; for($i=0;$i<$ARGV[0];$i++) { foreach $rcpt (@to) { $counter++; $date=GetCurTime(); $success=$smtp->mail($from); $success=$smtp->to($rcpt); $success=$smtp->data(); $smtp->datasend("From: $from/n"); $smtp->datasend("To: $rcpt/n"); $smtp->datasend("Subject: test$counter/n"); $smtp->datasend("Content-Type: text/plain;/n"); $smtp->datasend("Date: $date/n/n"); $smtp->datasend($body); $smtp->datasend("/n"); $success=$smtp->dataend(); } } print "/n$counter mails have been delivered to /"", $smtp->domain(),"/" successfully./n"; $smtp->quit(); sub GetCurTime() { $ctime=localtime(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $year+=1900; @month=qw(Jan Feb Mar Apr May June July Aug Sep Oct Nov Dec); $mon=$month[$mon]; $hour=($hour < 10 ? "0$hour":$hour); $min=($min < 10 ? "0$min":$min); $sec=($sec < 10 ? "0$sec":$sec); $date="$mday $mon $year $hour:$min:$sec +0800"; return $date; }

 

 

 

如转载,请注明出处:http://blog.csdn.net/zhangyang0402/archive/2009/11/01/4754782.aspx

你可能感兴趣的:(Perl定制并发送邮件)