1.安裝mailx郵件服務
yum -y install mailx
若有其他郵件服務器建議先停止常見如下
service sendmail stop
chkconfig sendmail off
service postfix stop
chkconfig postfix off
2.配置郵件服務
vim /etc/mail.rc
set from=xxxxx@aliyun.com # 公司授權個人的阿里企業郵箱 set smtp=smtps://smtp.exmail.qq.com:465 #設置smtp服務器 set smtp-auth-user=xxxxx@aliyun.com # 公司授權個人的阿里企業郵箱 set smtp-auth-password=xxxxx # 企業郵箱密碼 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/etc/mail/scripts/.certs #證書所在目錄
因為阿里雲 ECS 封禁了 25 端口,所以我們只能使用 TLS 方式(TSL 也就是使用 SSL 加密的方式,使用 465 或者其他端口來發送郵件)繞過 25 端口需求來發送郵件,
所以必須先獲得郵箱的 SSL 證書並存放到本地,最后一行的 nss-config-dir 就是制定的存放 QQ 郵箱 SSL 證書的位置。在末尾添加以下內容(或直備份源文件后直接更改源文件)
3.配置 騰訊企業郵箱的 SSL 證書
mkdir -p /etc/mail/scripts/.certs echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /etc/mail/scripts/.certs/qq.crt certutil -A -n "GeoTrust SSL CA" -t "C,," -d /etc/mail/scripts/.certs -i /etc/mail/scripts/.certs/qq.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d /etc/mail/scripts/.certs -i /etc/mail/scripts/.certs/qq.crt certutil -L -d /etc/mail/scripts/.certs/ cd /etc/mail/scripts/.certs/ && certutil -A -n "GeoTrust SSL CA – G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
4.為了防止出現前文所說的發送郵件警告提示,還需要進入郵箱 SSL 證書存放目錄 /etc/mail/scripts/.certs 里執行如下命令:
cd /etc/mail/scripts/.certs/ && certutil -A -n "GeoTrust SSL CA – G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
5.出現以下提示則為成功
**Notice: Trust flag u is set automatically if the private key is present.**
6.測試企業郵箱發送郵件
mailx -s "測試標題" aa@aliyun.com < 1.txt #單個收件人
mailx -s "測試標題" aa@aliyun.com bb@aliyun.com < 1.txt #多個收件人
注意事項#企業郵箱需要關閉安全登錄
本文參考以下博客
https://blog.csdn.net/ljj_18539663587/article/details/104821751
https://blog.csdn.net/lazyRabbitLLL/article/details/79718450
https://blog.espnlol.com/?p=335