我們知道阿里雲ECS服務器默認禁用25端口。所以我們可以使用465端口(郵件的ssl端口)來進行郵件的發送。
1.我們先在安全組開放465端口。
2.然后需要配置QQ郵箱的(SMTP服務的設置)。具體設置方法自行百度。在此不再說明。
3.在服務器上配置關閉其它的郵件工具
service sendmail stop chkconfig sendmail off 停止sendmail服務並取消開機自啟 (centos6.x)
service postfix stop chkconfig postfix off 停止postfix服務並取消開機自啟
4.安裝mailx。(Linux下一種郵件軟件)
yum install mailx -y
5.請求QQ郵箱數字證書
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’ > ~/.certs/qq.crt
certutil -A -n “GeoTrust SSL CA” -t “C,,” -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n “GeoTrust Global CA” -t “C,,” -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n “GeoTrust SSL CA – G3” -t “Pu,Pu,Pu” -d ~/.certs/./ -i qq.crt # 這里需要注意的是在執行這條命令時,所執行的路徑必須是/root/.certs/ 否則將會報錯
certutil -L -d /root/.certs
6.配置/etc/mail.rc
set from=2975502691@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=2975502691@qq.com
set smtp-auth-password=xxxx #授權碼
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
7.發送郵件並測試是否成功
echo “hello,world” | mail -s “測試郵件” 2975502691@qq.com