【发布时间】:2021-04-02 17:30:11
【问题描述】:
我正在尝试使用应用引擎标准使用客户端的本地 SMTP 服务器发送电子邮件。为此,我们在默认网络中创建了无服务器 VPC 访问连接器,并使用静态 IP 地址创建了 Cloud NAT 以发送出口流量。客户端已将静态 IP 地址和端口列入白名单。以下是应用引擎中的代码sn-p
msg.set_content('This is a HTML email')
msg.add_alternative(cleared_html_content, subtype='html')
try:
context = ssl._create_unverified_context()
print("starting conectn")
with smtplib.SMTP('xx.xxxx.edu', 2525) as server:
server.starttls(context=context)
server.send_message(msg)
print("sent almost")
except Exception as e:
print('Error: ', e)
下面是app.yaml
runtime: python37
entrypoint: gunicorn -t 120 -b :$PORT main:app
vpc_access_connector:
name: projects/xxxxxxxxx/locations/us-central1/connectors/yyyyyyyyy
当我使用应用程序引擎 url 运行我的应用程序时,我在日志查看器中收到以下错误
Error: (554, b"xxx.xxxxx.edu\nYour access to this mail system has been rejected due to the sending MTA's poor reputation. If you believe that this failure is in error, please contact the intended recipient via alternate means."
我还使用与应用程序引擎中相同的代码创建了云功能以进行测试,令人惊讶的是,电子邮件被发送到预期的收件人而没有任何问题。当我检查云 NAT 日志时,它具有通过云功能触发时的所有详细信息(简而言之,它使用静态 IP 地址)但没有与应用引擎触发器相关的日志。所以我认为我的应用引擎流量不是通过静态 IP 地址进行的,并且不知道如何在 app.yaml 中提及它
电子邮件功能中也可能存在代码问题,但由于它在云功能中工作,我真的怀疑我的 app.yaml 而不是电子邮件 python 代码。非常感谢任何帮助
【问题讨论】:
-
您如何访问您的 SMTP 本地 smtp 服务器?在公共 IP 还是私有 IP 上?
-
您正尝试以
open relay的身份向学校的电子邮件服务器发送电子邮件。这意味着您没有使用身份验证。如果您学校的电子邮件系统将 IP 地址列入白名单,则您连接的 IP 地址不在列表中。 -
@guillaumeblaquiere 我们为云 NAT 创建了静态公共 ip 并与学校共享,他们将其列入白名单。这就是云功能发送电子邮件没有任何问题的原因。
-
@JohnHanley 我同意。因此,当流量通过应用引擎时,它不使用被列入白名单的云 NAT IP 地址。但是通过云功能触发时使用白名单IP。那么为什么应用引擎不通过云 NAT 发送流量?
标签: google-app-engine google-cloud-platform google-cloud-functions