1. 环境&软件版本:
Centos 7.2
sendmail-8.14.7-6.el7.x86_64
mailx-12.5-19.el7.x86_64
2. 安装软件
[server /]# yum install -y sendmail [server /]# yum install -y mailx
3.修改配置文件
[server /]# vim /etc/mail.rc # 配置发送方地址 set from=xxxxxx@163.com # 配置邮件服务器,因为25端口管控比较严格,所以直接使用465端口 set smtp=smtps:\/\/smtp.163.com:465 # 登录邮箱账号 set smtp-auth-user=xxxxxxx@163.com # 登录密码,这个是独立的授权码,需要单独获取 set smtp-auth-password=xxxxxxxxxxxxxxx # 配置登录 set smtp-auth=login # 证书路径,因为使用465端口,需要使用ssl验证。 set nss-config-dir=/opt/.certs
4.生成SSL自签名证书
# 创建证书目录 [root@01 /]# mkdir -p /opt/.certs/ #生成证书 [root@01 /]# echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /opt/.certs/163.crt ...... depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA verify return:1 depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = GeoTrust CN RSA CA G1 verify return:1 depth=0 C = CN, ST = Zhejiang, L = Hangzhou, O = "NetEase (Hangzhou) Network Co., Ltd", OU = IT Dept., CN = *.163.com verify return:1 DONE # 添加证书至SSL证书库中 [root@01 /]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i /opt/.certs/163.crt # 添加证书至Global 证书库中 [root@01 /]#certutil -A -n "GeoTrust Global CA" -t "C,," -d /opt/.certs -i /opt/.certs/163.crt # 展示证书列表 [root@01 /]# certutil -L -d /root/.certs Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI GeoTrust Global CA C,, GeoTrust SSL CA P,P,P
5.启动sendmail
[root@01 /]# systemctl start sendmail
6.发送测试邮件
[root@01 /]# echo '测试' | mail -s '测试' 13591899785@163.com
FAQ:
问题1:
[root@01 ~]# could not connect: 连接超时
“/root/dead.letter” 11/306
. . . message not sent.
解决办法: 使用了默认的25端口,现在25管控比较严格,建议使用465
问题2:
Unexpected EOF on SMTP connection
“/root/dead.letter” 11/306
. . . message not sent.
解决办法:配置文件中邮件服务器地址写错了或者格式问题,参考上面的配置文件邮件服务器写法。
问题3:
Missing “nss-config-dir” variable.
“/root/dead.letter” 11/306
. . . message not sent.
解决办法: 配置文件中没有配置nss-config-dir 证书路径,参考上面配置文件进行配置
问题4:
Error in certificate: Peer’s certificate issuer is not recognized.
Continue (y/n)? SSL/TLS handshake failed: Peer’s certificate issuer is not recognized.
解决办法:证书有问题,参考上面生成证书
问题5:
smtp-server: 535 Error: authentication failed
解决办法:检查用户名密码,注意密码163或者qq邮箱的密码是一个授权码,不是平常登录用的密码哦。