最近要做一個定時任務錯誤資訊實時轉發到郵件,由于用的阿裡雲伺服器一直不成功,在網上找了下原因:
是因為阿裡雲伺服器關閉了25端口,發送郵件才會顯示連結逾時,而且官方不允許打開該端口,而且大部分郵件都是通過25端口,在網上找了個還不錯,以網易163郵箱為例,使用SSL下的465端口。
具體操作:
一、請求數字證書
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 ####列出目錄下證書
二、配置發件人
輸入指令: vi /etc/mail.rc
配置如下
點我領取阿裡雲2000元代金券 ,(阿裡雲優惠券的作用:購買阿裡雲産品,最後支付結算的時候,阿裡雲優惠券可抵扣一部分費用。For Linux and BSD, this should be set.
set bsdcompat
set smtp=smtps://smtp.163.com:465
set smtp-auth-password=xxxxxxx #此密碼為第三方登入密碼
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
三、測試
echo “test” | mail -s “zabbix” [email protected]
登陸收件人郵箱檢視
看似成功但是linux中報錯:證書不被信任
四、解決最後一個問題-----證書不被信任
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.
阿裡雲伺服器: 活動位址
購買可領取:
阿裡雲代金券