1.安裝mailx
yum install mailx -y
2.配置證書
mkdir -p /root/.certs
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
# 解決:Error in certificate:XXX
cd /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
若需要qq的ssl 只需把第二條命令中的smtp.xxx.com:465 給替換了就行。
3.修改mailx配置文件
vim /etc/mail.rc
在文件末尾添加:
我這裏配的是QQ郵箱,其中smtp-auth-password是授權碼不是密碼。
set bsdcompat
set sendcharsets=iso-8859-1,utf-8
set from=[email protected]
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=[email protected]
set smtp-auth-password=ABC123
set smtp-auth=login
set ssl-verify=ignore
# 證書地址
set nss-config-dir=/root/.certs
4.發送郵件測試
echo "zabbix test mail" |mail -s "zabbix" [email protected]
PS:
1.關於如何獲得QQ郵箱授權碼:
登錄QQ郵箱,–設置—賬戶