1. 程式人生 > >在阿裏雲上無法使用mailx發送郵件的解決辦法,驗證可用。

在阿裏雲上無法使用mailx發送郵件的解決辦法,驗證可用。

etc err 465端口 password 軟件包 請求 安全組 dir 企業

由於阿裏雲已將25端口封了(改用465端口),所以在ECS上往外發郵件時要作相應的配置才行。

使用的是163的企業郵箱,筆記簡潔可用。

在阿裏雲的“安全組”開放645端口通行。

1.安裝相應軟件包:

systemctl stop sendmail
systemctl stop postfix
systemctl disable sendmail
systemctl disable postfix
yum -y install mailx

2.下載證書:

#創建目錄,用來存放證書
mkdir -p /root/.certs/

#向163請求證書
echo -n|openssl s_client -connect smtp.qiye.163.com:465|sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p‘ > ~/.certs/163.crt

#添加一個證書到證書數據庫中
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

#使證書得到認可,避免發郵件後報錯:Error in certificate: Peer‘s certificate issuer is not recognized

cd /root/.certs (一定要進入到證書所在目錄才行)
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i ./163.crt

#列出目錄下證書
certutil -L -d /root/.certs

3.追加配置:

vim /etc/mail.rc

set from="[email protected]"
set smtp="smtps://smtp.qiye.163.com:465"
set [email protected]
set smtp-auth-password=123456789
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

4.測試效果:

echo ‘hello‘|mail -v -s "test mail" [email protected]

在阿裏雲上無法使用mailx發送郵件的解決辦法,驗證可用。