centos7安装mailx
1.安装mailx
yum install mailx -y
2.配置证书
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
certutil -L -d /root/.certs
# 解决:Error in certificate:XXX
cd /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
若需要qq的ssl 只需把第二条命令中的smtp.xxx.com:465 给替换了就行。
3.修改mailx配置文件
vim /etc/mail.rc
在文件末尾添加:
我这里配的是QQ邮箱,其中smtp-auth-password是授权码不是密码。
set bsdcompat
set sendcharsets=iso-8859-1,utf-8
set from=xxxxxxxx@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=xxxxxxxxxx@qq.com
set smtp-auth-password=ABC123
set smtp-auth=login
set ssl-verify=ignore
# 证书地址
set nss-config-dir=/root/.certs
4.发送邮件测试
echo "zabbix test mail" |mail -s "zabbix" xxx@126.com
PS:
1.关于如何获得QQ邮箱授权码:
登录QQ邮箱,–设置—账户