阿里云服务器发送邮件

1.阿里云限制了25端口的外出,改用465端口,

如果想申请通过:查看此地址

2.此处使用了163邮箱

2.1 mkdir -p /root/.certs/                           ####创建目录,用来存放证书

2.2 echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify return:1
depth=1 C = US, O = GeoTrust Inc., CN = GeoTrust SSL CA - G3
verify return:1
depth=0 C = CN, ST = ZheJiang, L = HangZhou, O = "NetEase (Hangzhou) Network Co., Ltd", CN = *.163.com
verify return:1
DONE

  2.3 certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

    ###添加一个证书到证书数据库中

发送邮件:echo 'test mail' | mail -s "zabbi2222222x" 326424553@qq.com

提示错误: Error in certificate: Peer's certificate issuer is not recognized.

解决:certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt

3. 配置vim /etc/mail.rc

set from=17737156701@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=17737156701@163.com
set smtp-auth-password=*********
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

参考资料:https://www.cnblogs.com/yunweis/p/8149242.html

原文地址:https://www.cnblogs.com/myvic/p/9354184.html