使用465埠加密發郵件
一、問題描述
今天由於服務需求,需要伺服器需要傳送郵件;但是不論用什麼辦法,傳送郵件總是失敗;最終發現原因:阿里雲實例伺服器預設禁止了25埠;
阿里雲回覆:
由於國際與國內均對垃圾郵件進行嚴格管控,我國《網際網路資訊服務管理辦法》、《中國網際網路協會反垃圾郵件規範》均對垃圾郵件進行說明與管理規範。 鑑於伺服器25埠被大量垃圾郵件充斥,嚴重影響廣大使用者正常使用。為了共同維護良好的網路環境,自即日起阿里雲新購伺服器不再提供25埠郵件服務, 建議您嘗試使用465加密埠傳送郵件。
所以研究了一下465埠傳送郵件
二、使用465埠加密傳送郵件
1、關閉其它的郵件工具
2、安裝mailx
[[email protected] ~]# yum install mailx
3、開啟smtp
在任何郵箱平臺中開啟smtp,開啟後會得到一個授權碼,這個授權碼就代替了密碼(自行去郵箱開啟)。我使用的是163郵箱
4、請求數字證書(這裡用的163郵箱,所以向163請求證書)
[[email protected] ~]# mkdir .certs
[[email protected] ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/.certs -i /root/.certs/163.crt
[[email protected] ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/.certs -i /root/.certs/163.crt
[[email protected] ~]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /root/.certs/./ -i /root/.certs/163.crt
Notice: Trust flag u is set automatically if the private key is present.
[[email protected] ~]# ls /root/.certs/
163.crt cert8.db key3.db secmod.db
[[email protected] ~]# certutil -L -d /root/.certs
Certificate Nickname Trust Attributes
SSL,S/MIME,JAR/XPI
GeoTrust SSL CA P,P,P
5、配置/etc/mail.rc
[[email protected] ~]# vim /etc/mail.rc
set from[email protected]163.com #之前設定好的郵箱地址 set smtp="smtps://smtp.163.com:465" #郵件伺服器 set [email protected]163.com #之前設定好的郵箱地址 set smtp-auth-password=xxxx #授權碼 set smtp-auth=login #預設login即可 set ssl-verify=ignore #ssl認證方式 set nss-config-dir=/root/.certs #證書所在目錄
6、傳送郵件測試
[[email protected] ~]# echo "郵件正文" | mail -s "郵件主題" [email protected]
郵件傳送成功