加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

一个用perl写的发邮件的脚本

发布时间:2020-12-15 21:05:41 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl =pod #send email common script #Angelo - 2008/10/06 ttachment] #EmailServer - emailserver. #port - listening port,default is 25 uard.com.set "" if no to-sendee uard.com.set "" if no cc-sendee #Subject?? - subject of your em

#!/usr/bin/perl
=pod
#send email common script
#Angelo - 2008/10/06
ttachment]
#EmailServer - emailserver.
#port - listening port,default is 25
uard.com.set "" if no to-sendee
uard.com.set "" if no cc-sendee
#Subject?? - subject of your email,string.set "" if no subject.
r.
#Attachment- full path of attachement,seperated by ",".

# Revision History
# Will Yi - 2011/12/30 - Added a command line argument to specify the debug level for send()
=cut
use MIME::Lite;
use strict;
#my $reportserver = 'ex01bd.bdc.wgti.net';
#my $port = '25';
#my $fromaddress? = 'local.test';
#my $reporttoaddress = 'angelo.liu@watchguard.com';

if ((scalar @ARGV) < 5 || (scalar @ARGV) > 9) {
??? &usage;
??? exit -1;
}
my $reportserver = $ARGV[0];
my $port = $ARGV[1];
my $fromaddress? = $ARGV[2];
my $reporttoaddress = $ARGV[3];
my $encode_type = $ARGV[4];
if ((scalar @ARGV) < 5 || (scalar @ARGV) > 9) {
??? &usage;
??? exit -1;
if ((scalar @ARGV) < 5 || (scalar @ARGV) > 9) {
??? &usage;
??? exit -1;
my $subject = 'automation_test';
my $body = 'automation test';
my $attachment = '';
my @attachlist;
if ($ARGV[5]) {
??? $subject = $ARGV[5];
if ($ARGV[5]) {
??? $subject = $ARGV[5];
}
if ($ARGV[5]) {
??? $subject = $ARGV[5];
}
??? $body = $ARGV[6];
if ($ARGV[6]) {
??? $body = $ARGV[6];
if ($ARGV[6]) {
??? $body = $ARGV[6];
}
if ($ARGV[7]) {
??? $attachment = $ARGV[7];
if ($ARGV[7]) {
??? $attachment = $ARGV[7];
if ($ARGV[7]) {
??? $attachment = $ARGV[7];
}
if ($ARGV[8]) {
??? $debug_level = $ARGV[8]; # 0-disable; 1-verbose
if ($ARGV[8]) {
??? $debug_level = $ARGV[8]; # 0-disable; 1-verbose
}
if ($ARGV[8]) {
??? $debug_level = $ARGV[8]; # 0-disable; 1-verbose

if (!($attachment eq '')) {
??? @attachlist = split(',',$attachment);
??? foreach my $eachattach (@attachlist) {
??????? -e $eachattach or die "$eachattach doesn't exists.n";
??? }
}
}
my $msg = MIME::Lite->new(
??? From???? => $fromaddress,
??? To?????? => $reporttoaddress,
??? Subject? => $subject,
??? Type???? => 'multipart/mixed',
??? Encoding => $encode_type,
);
);
$msg->attach(
??? #Type????? => 'AUTO',
??? Data????? => $body,
$msg->attach(
??? #Type????? => 'AUTO',
);
$msg->attach(
??? #Type????? => 'AUTO',
);
if (!($attachment eq '')) {
??? foreach my $eachattach (@attachlist) {
??????? $msg->attach(
??????? Path??????? => $eachattach,
??????? Type??????????? => 'AUTO',
??????? Disposition => 'attachment'
??????? );
??? }
}
}
$msg->send('smtp',$reportserver,Debug=>$debug_level,Port => $port);

.n";
??? print "EmailServert- emailserver address.n";
d.com,yyy@watchguard.com.set "" if no to-sendee.n";
??? print "EncodeTypet- should be 7bit/8bit/binaryn";
st one char.n";
t,default is 1n";
??? return 0;

?

使用方法如下:automation@net1PC1:~$ perl send_common_email.pl ?
Usage: send_common_email.pl <EmailServer> <port> <FromAddress> <ToAddress> <encode_type> [Subject] [Body] [Attachment] [Debug Level].
eg. send_common_email.pl ex01bd.bdc.wgti.net fromme@xx.com,yyy@xx.com.
EmailServer???? - emailserver address.
FromAddress???? - "From" address
ToAddress?????? - "to" address," if you have muti-sendee,eg: xxx@xx.com,yyy@xx.com.set "" if no to-sendee. EncodeType????? - should be 7bit/8bit/binary Subject???????? - subject of your email,string.set "" if no subject. Body??????????? - context of your email,it can be a string or a exist-file.can not be "".at least one char. Attachment????? - full path of attachement,". DebugLevel????? - Set the debug level when sending mail. Value 1-verbose,0-disable. If not set,default is 1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读