centos7使用mailx通过阿里云企业邮箱465端口发送邮件
目的是为了 前几篇,如果发现部署分支是生产分支,并且没有提交记录或者当日的提交,就通知运维检查.
请求数字证书
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.mxhichina.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/ali.crt
添加证书到证书数据库中
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/ali.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/ali.crt
列出目录下证书
certutil -L -d /root/.certs
yum -y install mailx
将/etc/mail.rc修改为下面格式
set smtp=smtps://smtp.mxhichina.com:465
set smtp-auth-password=password
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
执行
cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i ali.crt
有这个提示,说明SSL证书配置生成及安装完成 。不执行会导致发送提示证书不被信任,但是仍可以发送.
发送邮件
echo "jenkins test mail" | mail -s "jenkins" [email protected]
这里服务器时区需要+8小时计算
如果发送失败 检查文件夹权限和文件权限并根据报错查看