1. 程式人生 > >使用465端口加密發郵件

使用465端口加密發郵件

聯網 得到 client 使用 verify end name mail xxx

一、問題描述

今天由於服務需求,需要服務器需要發送郵件;但是不論用什麽辦法,發送郵件總是失敗;最終發現原因:阿裏雲實例服務器默認禁止了25端口;

阿裏雲回復:

  由於國際與國內均對垃圾郵件進行嚴格管控,我國《互聯網信息服務管理辦法》、《中國互聯網協會反垃圾郵件規範》均對垃圾郵件進行說明與管理規範。 鑒於服務器25端口被大量垃圾郵件充斥,嚴重影響廣大用戶正常使用。為了共同維護良好的網絡環境,自即日起阿裏雲新購服務器不再提供25端口郵件服務, 建議您嘗試使用465加密端口發送郵件。

所以研究了一下465端口發送郵件

二、使用465端口加密發送郵件

1、關閉其它的郵件工具

[[email protected] ~]# systemctl stop sendmail
[[email protected] ~]# systemctl stop postfix

2、安裝mailx

[[email protected] ~]# yum install mailx

3、開啟smtp

在任何郵箱平臺中開啟smtp,開啟後會得到一個授權碼,這個授權碼就代替了密碼(自行去郵箱開啟)。我使用的是163郵箱

4、請求數字證書(這裏用的163郵箱,所以向163請求證書)

[[email protected] ~]# mkdir .certs

[[email protected] ~]# echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p‘ > /root/.certs/163.crt

[[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 [email protected] #之前設置好的郵箱地址
set smtp="smtps://smtp.163.com:465" #郵件服務器
set [email protected] #之前設置好的郵箱地址
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]

郵件發送成功

使用465端口加密發郵件