1 安装Mailx
yum install mailx -y
2 添加配置文件
vim /etc/mail.rc
# 企业邮箱地址
set from=test@test.com
# 腾讯企业邮箱发送服务器
set smtp=smtps://smtp.exmail.qq.com:465
# 企业邮箱地址
set smtp-auth-user=test@test.com
# 密码
set smtp-auth-password=123
# 验证方式
set smtp-auth=login
# 是否验证SSL证书
set ssl-verify=ignore
# 证书路径
set nss-config-dir=~/.certs
3 生成证书
mkdir ~/.certs
cd ~/.certs/
echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > qq.crt
certutil -A -n 'GeoTrust SSL CA' -t 'C,,' -d ./ -i qq.crt
certutil -A -n 'GeoTrust Global CA' -t 'C,,' -d ./ -i qq.crt
certutil -L -d ./
为了防止出现前文所说的发送邮件警告提示,还需要进入邮箱 SSL
证书存放目录 ~/.certs
里执行如下命令:
certutil -A -n 'GeoTrust SSL CA – G3' -t 'Pu,Pu,Pu' -d ./ -i qq.crt
返回如下提示即可:
Notice: Trust flag u is set automatically if the private key is present.
4 测试验证
echo "ceshi" | mail -s "test" poc@126.com