zabbix配置STMP使用SSL發送郵件報警
安裝mail
#CentOS
yum install -y mailx
配置STMP(/etc/mail.rc) 尾行追加
set from=m*******[email protected] smtp=smtp.163.com
set smtp-auth-user=m*******[email protected]
set smtp-auth-password=m*****3
set smtp-auth=login
測試郵件是否能發送
echo "hehe" | mail -s 'hhaa' z*********@163.com
zabbix配置STMP使用SSL發送郵件報警zabbix配置STMP使用SSL發送郵件報警 使用SSL/TLS
mkdir -p /root/.certs/
# 建立目錄,用來存放證書;
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
# 向163請求證書;
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
# 添加一個SSL證書到證書資料庫中;
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
# 添加一個Global 證書到證書資料庫中;
certutil -L -d /root/.certs
# 列出目錄下證書;
cd /root/.certs/ && certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt
# 讓證書受信任;
Notice: Trust flag u is set automatically if the private key is present.
# 如上輸出為成功;
添加mail.rc配置檔案
set ssl-verify=ignore
set nss-config-dir=/root/.certs
編寫發送郵件腳本
如果不進行格式轉換或者是替換,可以看到結尾帶有win的換行符^M,這會導緻郵件發不出去而發生554的錯誤。解決辦法有兩種分别是dos2unix進行格式轉換或是文本處理器替換。
#!/bin/bash
contact=$1
subject=$2
body=/tmp/mailx.log
echo "$3" >$body
/usr/bin/dos2unix $body
#sed -i 's/^M/\n/g' $body && sed -i 's/[[:space:]]//' $body
mail -s "$subject" "$contact" < $body
測試成果
zabbix配置STMP使用SSL發送郵件報警zabbix配置STMP使用SSL發送郵件報警 觸發報警
zabbix配置STMP使用SSL發送郵件報警zabbix配置STMP使用SSL發送郵件報警