由於ECS服務器安全問題,發送郵件統一使用SSL模式
安裝開始:
第一步:
Yum安裝mailx:yum install -y mailx
第二步:
創建證書存放目錄(如以存在無需創建):mkdir -p /root/.certs
生成SSL安全證書:
echo -n | openssl s_client -connect smtp.126.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /root/.certs/126.crt #向126請求證書 certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/.certs -i /root/.certs/126.crt #添加一個證書到證書數據庫中 certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/.certs -i /root/.certs/126.crt #添加一個證書到證書數據庫中 certutil -L -d /root/.certs #列出指定目錄下的證書 certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /root/.certs -i /root/.certs/126.crt #指明受信人證書、防報錯
第三步:
修改配置文件:vi /etc/mail.rc
在最下面添加郵箱發送配置:
set from=xxx@126.com #發送郵件后顯示的郵件發送方 set smtp=smtps://smtp.126.com:465 #SMTP服務器的網址 set smtp-auth-user=xxx@126.com #發送的郵箱 set smtp-auth-password=xxx #設置的密碼,客戶端授權密碼,步驟三自行設置的密碼 set smtp-auth=login #動作、登錄 #set smtp-use-starttls=false #安全連接傳輸 (此選項開啟后會報454錯誤,注釋掉可正常發郵件,發帖時未解決待測試) set ssl-verify=ignore #ssl驗證忽略 set nss-config-dir=/root/.certs #證書存放目錄
第四步:
管道符方式測試郵件發送,格式:echo "郵件內容" | mail -s "郵件主題" 接收者郵箱,例子如下
echo "測試郵件發送" | mail -s "測試" xxx@dingtalk.com