一,系統ubuntu16.04
https://support.google.com/mail/answer/7126229?hl=zh-Hans
https://support.google.com/accounts/answer/185839
gmai開啟imap
google賬號開啟二次認證,然後在生成應用密碼
sudo apt-get install heirloom-mailx
sudo vim /etc/s-nail.rc
set from="[email protected]"
set smtp="smtps://smtp.gmail.com:465"
set smtp-auth-user="[email protected]"
set smtp-auth-password="xxx" 應用密碼
set smtp-auth=login
二,測試
echo 'this is test' | s-nail -s "test email" [email protected]
echo 'this is test' |mail -s "test emai" [email protected]
三,配置zabbix_server
grep -i>
### Option: AlertScriptsPath
# Full path to location of custom alert>
# AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/lib/zabbix/alertscripts
### Option: ExternalScripts
# Full path to location of external>
# ExternalScripts=${datadir}/zabbix/externalscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
cat /usr/lib/zabbix/alertscripts/send_mail.sh
#!/bin/bash
messages=`echo $3 | tr '\\r\\n' '\\n'`
subject=`echo $2 | tr '\\r\\n' '\\n'`
echo "${messages}" | mail -s "${subject}" $1 >>/tmp/sendmail.log 2>&1
grep zabbix /etc/passwd
zabbix:x:113:118::/var/lib/zabbix/:/bin/false
usermod -s /bin/bash zabbix
/usr/lib/zabbix/alertscripts/send_mail.sh [email protected] test test
四,配置zabbix_web
1,創建報警媒介並關聯到動作
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
2,創建用戶並配置報警媒介,普通用戶要提升為管理員才發郵件
3,創建動作才會收到郵件:這個動作與sendmail關聯
四,排錯查看sendmail.log
tailf /tmp/sendmail.log
smtp-server: 553 5.1.3 address. a11sm8042272qkg.133 - gsmtp
smtp-server: 553-5.1.3 The recipient address is not a valid RFC-5321
smtp-server: 553 5.1.3 address. i13sm8479355qkk.78 - gsmtp
... message not sent
... message not sent
... message not sent
##############2020-02-03_04:15:46##########################
smtp-server: 553-5.1.3 The recipient address is not a valid RFC-5321
smtp-server: 553 5.1.3 address. 2sm8610543qkv.98 - gsmtp
... message not sent
閱讀更多 呆萌講運維 的文章