使用场景:
阿里云服务器centos7(linux)+发送端:163邮箱+接收端:qq邮箱
准备:
163邮箱配置
QQ邮箱配置
开始配置
阿里云封闭25端口,所以不能通过默认的端口(25)发送邮箱服务,需要通过邮箱服务器的加密端口(465)来完成发送邮件的服务。配置流程如下:
① 修改 /etc/mail.rc 末尾处加入
【利用163邮箱发送,最后一句是证书存放位置,届时发送邮件的时候,会通过此证书,来对加密端口进行解密,此处加密端口是465】
set bsdcompat
set from=xxx@163.com//xxx:自己的163邮箱
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=xxx@163.com//xxx:同上
set smtp-auth-password=xxxxxx//xxxxxx:准备阶段获得的授权码
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/mail_cert//证书存放位置,后叙
② 然后是创建文件夹来放证书文件,执行如下命令行
mkdir -p /root/mail_cert
执行命令:
echo -n "" | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /root/mail_cert/163.crt
certutil -A -n "GeoTrust SSL CA"-t "C,," -d /root/mail_cert -i 163.crt
certutil -A -n "GeoTrust Global CA"-t "C,," -d /root/mail_cert -i 163.crt
certutil -L -d /root/mail_cert
执行后即可发送邮件:
测试:
echo "TEST" | mail -v -s "Title" xxxx@qq.com
这里:xxxx@qq.com指目标邮箱
邮件可以发送但是会有警告
警告可以忽视,若想去掉警告,则在刚才证书目录/root/mail_cert下执行
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /root/mail_cert -i 163.crt
出现如下表示设置成功
Notice: Trust flag u is set automatically if the private key is present.
Done:
准备阶段的图来源:
以上感谢