perl使用MIME::Lite发信的例子,发送日志文件的最后50行。
供大家学习参考。
use warnings;
use strict;
use MIME::Lite;
my $file1='/tmp/parse_fund_rel_log.log';
my $file2='/tmp/parse_news_log.log';
my $f1=`tail -50 /tmp/parse_fund_rel_log.log`;
my $f2=`tail -50 /tmp/parse_news_log.log`;
my $code = system(" tar cvzf /tmp/parse_log.tar.gz /tmp/parse_news_log.log /tmp/parse_fund_rel_log.log ") ;
#print $code;
my $msg = MIME::Lite->new (
From => 'aa@jb200.com',
To => 'bb@jb200.com',
Cc => 'cc@jb200.com',
Subject => 'parse_log ',
Type => 'multipart/mixed'
);
$msg->attach(
Type => 'TEXT',
Data => "$file1 n $f1 nn $file2n $f2"
);
$msg->attach(
Type => 'auto',
Path => '/tmp/parse_log.tar.gz',
);
$msg->send('smtp',
'smtp.exmail.qq.com',
AuthUser =>'aa@jb200.com',
AuthPass =>'11'
);
my $code2 = unlink "/tmp/parse_log.tar.gz";