【发布时间】:2019-03-06 00:41:33
【问题描述】:
App Engine 允许人们收听收到的电子邮件。然后我想阅读附件并将它们写入 GCS 存储桶。 google.cloud.storage 在标准环境中不可用,而可用的cloudstorage 不允许在除默认存储桶之外的任何其他存储桶中写入。
我也在灵活的环境中尝试过,但 InboundMailHandler 在这种情况下不可用:“App Engine 邮件服务在标准环境之外不可用”https://cloud.google.com/appengine/docs/flexible/python/migrating
有没有办法在标准环境中将这些文件写入指定的存储桶?
import logging
import webapp2
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
class LogSenderHandler(InboundMailHandler):
def receive(self, mail_message):
logging.info("Received a message from: " + mail_message.sender)
plaintext_bodies = mail_message.bodies('text/plain')
html_bodies = mail_message.bodies('text/html')
if hasattr(mail_message, 'attachments'):
for filename, filecontent in mail_message.attachments:
# write filecontent to a bucket
app = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)
【问题讨论】:
标签: python google-app-engine google-cloud-storage