Python接口测试脚本部署到服务器端:Linux 发送邮件失败问题

接上篇,一直研究在Linux环境下发送邮件失败的问题。
处理思路是先配置Linux发送邮件成功,或许Python发送邮件才能成功。
按照网上找的很多博客进行配置,看起来超级easy,自己搞起来就费时费力 ~~ “一看就会,一做就废”,真是放在各种地方都很适用啊。

  1. 先按照大部分博文进行配置
    –> Install sendmail
    –> vi /etc/mail.rc
    set from=xxxxxx@126.com
    set smtp=smtps://smtp.126.com:465 (25端口可能被禁,所以改用465)
    set smtp-auth-user=xxxxxxxx@126.com
    set smtp-auth-password=xxxxxxxx (126网易邮箱的授权码)
    set smtp-auth=login
    set ssl-verify=ignore
    set nss-config-dir=/root/.certs (虽然写入了,但是后面需要执行命令使其生效)
    –> 启用sendmail
    启动 /bin/systemctl start sendmail.service
    停止 /bin/systemctl stop sendmail.service
    查看状态 /bin/systemctl status sendmail.service
    –> 尝试发送邮件: 发送失败
    mail -s “hesaucaq” xxx@xx.com
    –> 查看邮件日志命令: vi /var/log/maillog

  2. 翻博客,可能需要修改hostname
    临时修改:hostname mail.xxx.com
    永久修改:vi /etc/sysconfig/network
    hostname=mail.xxx.com
    hostname mail.xxx.com
    /bin/systemctl restart sendmail.service

  3. 再次运行,还是失败
    –> 编辑mail.rc时,加了一句set nss-config-dir=/root/.certs ,但是事实上,路径下根本没有文件。手动创建并执行命令:

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

–> 保存并重新运行,邮件能发送了,但是还是有error:
“Error in certificate: Peer’s certificate issuer is not recognized.”
此时,进入到.cert路径下,运行命令:

certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu"  -d ./ -i 126.crt

再次发送邮件,成功~ 发给不是126的邮箱号也是可以成功的。

虽然问题解决了,但是过程还是不能说完全理解透彻。
参考博客:
https://blog.csdn.net/djhsun/article/details/78731683

  1. Linux自身发送邮件可以成功了之后,根据mail.rc的配置更改Python代码中的config文件内容,修改为对应的smtp为126,端口号为465,终于可以成功发送邮件了~
    But, 为何接收方也只能是126邮箱呢,其他邮箱就会发送失败…
    在这里插入图片描述
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值