由于阿里云关闭了25端口,所以需要修改mailx端口改为465发送邮件

安装Mailx

yum install -y mailx

开启SMTP服务并获取授权码

登录邮箱-设置-账户
1、开启SMTP服务
2、获取授权码

设置mail.rc

在/etc/mailx.rc最后一行添加

set from=XXXXXXXX@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=XXXXXXXXX@qq.com
#邮箱SMTP授权码
set smtp-auth-password=*********
set smtp-auth-login
set ssl-verify=ignore
set nss-config-dir=/tmp/.certs

设置证书

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
cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i qq.crt
certutil -L -d /root/.certs
cp -a /root/.certs/ /tmp/

测试

echo "content" | mail -s "title" XXXXXXXX@qq.com