1、安装mailx(Centos7默认已安装)
yum install mailx
2、创建证书(以QQ邮箱为例)
1) mkdir -p /root/.certs/
2) echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
3) certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
4) certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
5) certutil -L -d /root/.certs
3、配置QQ邮箱发送邮件
开启SMTP服务,获取授权码:登录QQ邮箱,点击设置,点击账户开启相关服务
4、在配置文件 vim /etc/mail.rc 末尾添加
set from=xxx@qq.com #开启SMTP服务的邮箱 set smtp=smtps://smtp.qq.com:465 set smtp-auth-user=xxx@qq.com set smtp-auth-password=xxxxxx #邮箱的授权码 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/root/.certs #证书所在目录
5、发送测试邮件
echo hello word | mail -s " title" xxx@qq.com #此时QQ邮箱会收到一封邮件
看起来已经成功了,但是发送完邮件还有报错:证书不被信任,且命令行就此卡住,需要按键才能出现命令提示符
到证书所在目录:cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
至此,所有配置完成! |