1、安装msmtp:
wget http://downloads.sourceforge.net/msmtp/msmtp-1.4.30.tar.bz2?big_mirror=0
rhel5.7使用下面的版本:
wget http://downloads.sourceforge.net/msmtp/msmtp-1.4.17.tar.bz2?big_mirror=0
tar jxvf msmtp-1.4.30.tar.bz2
2、安装
cd msmtp-1.4.30 && configure --prefix=/usr/local/msmtp
make
make install
3、配置msmtp账号
cd /usr/local/msmtp && mkdir etc
使用vi新建文件,输入:vi /usr/local/msmtp/etc/msmtprc ,编辑内容如下:
# Set default values for all following accounts.
defaults
logfile /usr/local/msmtp/msmtp.log
# The SMTP server of the provider.
account zycloudalarm
host smtp.exmail.qq.com
from [email protected]
auth login
user [email protected]
password cloud123
account default : zycloudalarm
测试:
/usr/local/msmtp/bin/msmtp [email protected]
4、安装mutt:
yum install -y mutt
vi /etc/Muttrc.local ,编辑mutt的总设置,修改以下几行
set from="[email protected]"
set sendmail="/usr/local/msmtp/bin/msmtp"
set use_from=yes
set realname="Zhengyuan Cloud Alarm"
set editor="vi"
echo "测试" |mutt -s "测试" [email protected]
5、配置告警脚本
/etc/zabbix/alertscripts/muttmail.sh
#!/bin/bash
# $1 sendmail address
# $2 sendmail subject
# $3 file
echo "$3" | mutt -s "$2" $1
chmod +x /etc/zabbix/alertscripts/muttmail.sh
6、如果遇到中文乱码,在Muttrc.local中添加下面配置:
charset-hook ^us-ascii$ gb2312 # 用gb2312编码显示未设置编码的信件
charset-hook ^big5$ big5 # 用big5编码显示繁体信件
charset-hook !utf-8 gb2312 # 用gb2312编码显示非utf-8编码的信件
set assumed_charset = "gb2312" # 用gb2312编码显示未经MIME编码的信件
set rfc2047_parameters = yes # 用gb2312编码显示中文附件名