1、安装cpan
yum install perl-CPAN
2、用cpan安装脚本中用的的模块
perl -MCPAN -e shell
install MIME::Base64
install Encode
install MIME::Lite
install Authen::SASL
3、发送邮件的脚本alarm
#!/usr/bin/perl
use MIME::Base64;
use Encode;
use MIME::Lite;
use Authen::SASL;
my $pass='*******';
my $user='*******@163.com';
my $str="MHA切换报警";
$str = "=?utf-8?B?".encode_base64($str, "?=");
my $mymail = new MIME::Lite
From => '*******@163.com',
To => '*******@qq.com',
Subject => "$str",
HTMLCharset => 'utf-8',
TextCharset => 'utf-8',
TextEncoding => 'base64',
Data => ("MHA切换报警:详情请查看附件。");
HTMLEncoding => 'base64',
Debug => 1;
$mymail -> attach(Type => 'auto',Path => '/etc/mha/app1/manager.log');
$mymail -> send('smtp','smtp.163.com',Timeout=>60,AuthUser=>$user, AuthPass=>$pass);
4、在MHA的配置文件中加入调用信息
report_script=/data/mha/alarm