zabbix告警发邮件

时间:2021-12-10 08:50:05

wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz

配置sendEmail

yum -y install perl-Net-SSLeay perl-IO-Socket-SSL   # 安装组件

tar xf sendEmail-v1.56.tar.gz -C /usr/src/

ll /usr/local/src/sendEmail-v1.56/

cd /usr/local/src/sendEmail-v1.56/

cp -a sendEmail /usr/local/bin/

sh-4.1# pwd

/etc/zabbix/alertscripts 配置文件中有定义

vim sendmail.sh

#!/bin/bash

to=$1

subject=$2

body=$3

/usr/local/bin/sendEmail  -f 用户名A@126.com -t "$to" -s smtp.126.com -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu 用户名A@126.com -xp '密码' -m "$body"

 chmod +x sendEmail.sh
 chown zabbix.zabbix sendEmail.sh

各个参数的解释:

  -f:发件人邮箱 -t:收件人邮箱 -u:主题 -o:选项 -xu:用户名 -xp:密码 -m:邮件正文
注:163、qq邮箱需要到设置下面生成授权码,用授权码代替密码才能成功发送邮件

sh-4.1# ./sendmail.sh 用户名B@qq.com 2017 2017 使用传参数的方法来验证邮件发送成功给别人发

Mar 09 16:17:39 zabbix sendEmail[4917]: Email was sent successfully!

sh-4.1# ./sendmail.sh 用户名A@126.com  2018 209999 给自己发都可以

Mar 09 16:18:44 zabbix sendEmail[4931]: Email was sent successfully!

You have new mail in /var/spool/mail/root

centos 7


#!/bin/bash

to=$1

subject=$2

body=$3

#/usr/local/bin/sendEmail  -f  用户名@126.com -t "$to" -s smtp.126.com -u "$subject" -o message-content-type=html -o message-charset=utf8 -o tls=no -xu 用户名@126.com -xp '密码' -m "$body"

/usr/local/bin/sendEmail  -f 手机号@139.com -t "$to" -s smtp.139.com -u "$subject" -o message-content-type=html -o message-charset=utf8 -o tls=no -xu 手机号@139.com -xp '密码' -m "$body"

注:163、qq邮箱需要到设置下面生成授权码,用授权码代替密码才能成功发送邮件

 也可以参考http://blog.csdn.net/ronnyjiang/article/details/51456972

  139手机报警测试正常:

#!/bin/bash

to=$1

subject=$2

body=$3

/usr/local/bin/sendEmail  -f 手机号@139.com -t "$to" -s smtp.139.com -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu 手机号@139.com -xp '邮箱密码' -m "$body"


zabbix邮箱告警的详细配置


http://www.iyunv.com/thread-250588-1-1.html

http://blog.csdn.net/tianhua79658788/article/details/52773416


http://www.mamicode.com/info-detail-1127936.html  

Zabbix主动模式配置