阿里雲ECS實例郵件發送不了的解決辦法

最近要做一個定時任務錯誤信息實時轉發到郵件,由於用的阿里雲服務器一直不成功,在網上找了下原因:

是因爲阿里雲服務器關閉了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

配置如下

For Linux and BSD, this should be set.

set bsdcompat

set [email protected]

set smtp=smtps://smtp.163.com:465

set [email protected]

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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章