Centos7使用smtps 465端口发送邮件

系统:Centos7

环境:阿里云ECS

描述:

使用/etc/mail.rc配置发送邮件,想必大部分运维都配置过,这次新搭建了zabbix-server在配置邮件报警的时候,使用之前的配置方式,但是卡在连接到smtp服务器上,在各种排查后最后查到是因为阿里云对25端口不开放,所以这次使用smtps协议也就是465端口来发送邮件

Resolving host smtp.ym.163.com . . . done.
Connecting to 59.111.176.117:smtp . . .Connecting to 59.111.176.117:smtp . . .^C

配置方式

在/etc/mail.rc增加如下配置:

########################################
set from="[email protected]"
set smtp="smtps://smtp.ym.163.com:465"
set smtp-auth-user="[email protected]"
set smtp-auth-password="xiaoke-password"
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb
########################################

验证

echo "sometext"|mail -s "my subject" 要发送的邮箱地址

更新

在使用以上方式配置后,可以发送邮件但是会提示Error in certificate: Peer's certificate issuer is not recognized.
解决方法:

mkdir /root/.certs
echo -n | openssl s_client -connect smtp.ym.163.com:465| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.com.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.com.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.com.crt
certutil -L -d /root/.certs

完成之后将/etc/mail.rc里面的set nss-config-dir=/etc/pki/nssdb修改为/root.certs

猜你喜欢

转载自blog.51cto.com/kexiaoke/2122335