使用Python3的AppEngine StdEnv:如何接收传入电子邮件

时间:2019-02-13 06:11:42

标签: python-3.x email google-app-engine google-cloud-platform

当前文档: 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上接收传入电子邮件的任何文档。我尝试过:

app.yaml

runtime: python37
entrypoint: gunicorn -b :$PORT incoming_email.app
handlers:
- url: /_ah/mail/.+
  script: auto
  login: admin
inbound_services:
- mail

requirements.txt

ez_setup
gunicorn
google-appengine

incoming_email.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.

需要使用google-appengine来导入InboundMailHandler,但是看起来google-appengine pip安装是否适用于Python 2?有人可以使用Python3接收电子邮件吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

App Engine标准环境上的Python 3运行时与Python 2运行时明显不同。

official documentation for the differences between Python 2 and Python 3 on the App Engine standard environment中所述:

  

邮件服务在Python 3中不可用。您需要使用第三方邮件提供程序(例如SendGrid,Mailgun或Mailjet)发送电子邮件。所有这些服务都提供了API,用于从应用程序发送电子邮件。

在App Engine标准Python 3运行时环境中,您可以找到官方文档中涵盖的2个选项:

这两个邮件API均可接收和解析入站电子邮件。