升级Ubuntu及Python后Google SMTP Relay生产服务器发件失败求助
背景与正常配置
我基于Ubuntu的Web服务器需要偶尔发送邮件,使用的Python代码如下:
with smtplib.SMTP('smtp-relay.gmail.com', 587, 'mydomain.com') as s: s.sendmail(fromaddr, toaddr, msg.as_string()) s.quit()
此前配置满足以下条件,稳定运行6个多月:
- 拥有Google Workspace账号
- 使用IP认证(非SMTP账号密码认证)
- 已将测试服务器(本地)和生产服务器(云端)的IP添加至SMTP Relay可信IP列表
故障现象
两天前完成升级后出现问题:
- Ubuntu从20LTS升级至22LTS
- Python从3.8升级至3.10
目前测试服务器(原地升级)邮件发送正常,但生产服务器(新建实例后转移原IP)持续抛出错误:
Invalid credentials for relay [...]. The IP
5.7.1 address you've registered in your G Suite SMTP Relay
service doesn't
5.7.7 match domain of the account this email is being sent from. If you are
5.7.1 trying to relay mail from a domain that isn't registered under your G
5.7.1 Suite account or has empty envelope-from, you must configure your
5.7.1 mail server either to use SMTP AUTH to identify the sending domain or
5.7.1 to present one of your domain names in the HELO or EHLO command. For
5.7.1 more information, please visit
https://support.google.com/a/answer/6140680#invalidcred ...
排查进展与推测
启动云端旧Ubuntu服务器,将其新IP添加至Google可信IP列表后,邮件发送正常。目前怀疑三种可能性:
- Google通过某种方式识别并信任旧设备的请求(尽管IP已变更)
- Linode未正确转发生产服务器的IP地址
- Ubuntu升级过程中出现配置故障
这些推测都比较离奇,但仍在持续排查。
额外补充信息
- 测试服务器为原地升级,生产服务器是新建实例,确认其他功能正常后将原IP转移至新实例
- 登录Google管理后台查看可信IP列表,显示的IP与测试服务器一致;生产服务器仅能通过SSH管理,无法直接查看对外IP
- 看到非官方信息称Google SMTP Relay需要配置反向DNS(rDNS),已为生产服务器配置该条目20小时,但仍报错;测试服务器未配置rDNS却能正常发件(测试服务器可访问互联网,但无静态IP)
- 发件邮箱为
someuser@mydomain.com(非@gmail.com格式) - 生产服务器托管于Linode
此前看过类似问题的讨论,但内容聚焦于SMTP登录验证,而我的配置一直使用IP认证,且在8月12日(周五)前均正常运行。
内容的提问来源于stack exchange,提问作者Dr Phil

