python-3.x - 使用 Python3 的 AppEngine StdEnv:如何接收传入的电子邮件
问题描述
当前文档: https ://cloud.google.com/appengine/docs/standard/python/mail/receiving-mail-with-mail-api
看起来它是针对 python27 的,否则在 app.yaml 中的条目应该是:
- url: /_ah/mail/.+
script: auto (instead of handle_incoming_email.app)
login: admin
我找不到任何关于如何使用 Python3 在 GAE StdEnv 上接收传入电子邮件的文档。我试过:
应用程序.yaml
runtime: python37
entrypoint: gunicorn -b :$PORT incoming_email.app
handlers:
- url: /_ah/mail/.+
script: auto
login: admin
inbound_services:
- mail
要求.txt
ez_setup
gunicorn
google-appengine
传入电子邮件.py
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
import webapp2
class LogSenderHandler(InboundMailHandler):
"""."""
def receive(self, mail_message):
"""Do things with mail_message"""
app = webapp2.WSGIApplication([
('/_ah/mail/', LogSenderHandler)
], debug=True)
但是在部署时,google-appengine 无法构建:
Error ID: 4646FF8A. Error type: InternalError. Error message: `pip_download_wheels` had stderr output: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-wheel-80z20v2n/google-appengine/
error: `pip_download_wheels` returned code: 1.
导入 InboundMailHandler 需要 google-appengine,但看起来 google-appengine pip install 适用于 Python 2?任何人都可以使用 Python3 接收电子邮件?
谢谢!
解决方案
App Engine 标准环境中的 Python 3 运行时与 Python 2 运行时有很大不同。
正如官方文档中关于 App Engine 标准环境中 Python 2 和 Python 3 之间的差异的说明:
邮件服务在 Python 3 中不可用。您需要使用第三方邮件提供商,例如 SendGrid、Mailgun 或 Mailjet 来发送电子邮件。所有这些服务都提供 API 来从应用程序发送电子邮件。
在 App Engine 标准 Python 3 运行时环境中,您可以找到官方文档中介绍的 2 个选项:
这两个邮件 API 都可以接收和解析入站电子邮件。
推荐阅读
- c# - Socket.ReceiveAsync 未调用 e.Completed 事件
- node.js - 打开 SSL3.0 - 使用节点 17.0
- javascript - “未处理的拒绝(错误):重新渲染太多......”因为我在循环中设置状态?
- tensorflow - 关于为 Google Magenta AI 音乐项目(DDSP 模块)创建或查找吉他预训练 wights
- php - SQLite3 LIMIT for UPDATE 和 DELETE 在 Windows 中的 PHP 上?
- react-native - TypeError:未定义不是对象(评估'Object.keys(params)')
- c++ - 在 C++ 中迭代枚举类的常用方法是什么?
- sql - 将 SQL 查询从 with 子句转移到没有 with 子句
- grails - grails如何检查双负零
- node.js - 是否有一个选项可以向我显示特定 npm 包的哪些语义版本将解析为?