1、依赖安装
yum install perl-Net-SSLeay perl-IO-Socket-SSL -y
2、下载sendmail
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
tar -zxvf sendEmail-v1.56.tar.gz -C /tmp
cd /tmp/sendEmail-v1.56
cp -a sendEmail /usr/local/bin
chmod +x /usr/local/bin/sendEmail
3、本机自测
/usr/local/bin/sendEmail -f from@qq.com -t to@qq.com -s smtp.qq.com -u "我是邮件主题" -o message-content-type=html -o message-charset=utf8 -xu from@qq.com -xp 123456 -m "我是邮件内容" -l /var/log/sendMyEmail.log
命令说明:
/usr/local/bin/sendEmail 命令主程序
-f from@qq.com 发件人邮箱
-t to@qq.com 收件人邮箱
-s smtp.qq.com 发件人邮箱的smtp服务器
-u "我是邮件主题" 邮件的标题
-o message-content-type=html 邮件内容的格式,html表示它是html格式
-o message-charset=utf8 邮件内容编码
-xu from@qq.com 发件人邮箱的用户名
-xp 123456 发件人邮箱密码
-m "我是邮件内容" 邮件的具体内容
-l /tmp/sendMyEmail.log 日志记录
4、zabbix服务端配置
根据配置文件zabbix_server.conf 找到参数AlertScriptsPath
#AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
路径下新增配置文件
vim sendEmail.sh
#!/bin/bash
to=$1
subject=$2
body=$3
/usr/local/bin/sendEmail -f zabbix@qq.com -t "$to" -s smtp.qq.com -u "${subject}" -o message-content-type=html -o message-charset=utf-8 -xu qq邮箱 -xp QQ邮箱密码 -m "$body"
授权
chmod +x sendEmail.sh
chown zabbix.zabbix sendEmail.sh
5、zabbix web端配置
进入zabbix管理页面 管理->报警媒介类型 点击最右边的创建媒体类型