【问题标题】:Receiving mail using Bottle on Google App Engine在 Google App Engine 上使用 Bottle 接收邮件
【发布时间】:2012-09-04 00:54:34
【问题描述】:

我是编程新手。我在 GAE 上使用瓶子。我想接收和阅读邮件(如果可能的话)。

这是我的 app.yaml 文件:

- url: /_ah/mail/contact@appid.appspotmail.com
  script: main.py
  login: admin

inbound_services:
- mail 

这是(应该是)我在 main.py 文件中的邮件处理程序:

from google.appengine.api import mail
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler

@route('/_ah/mail/contact@appid.appspotmail.com', method = 'POST')
def receive_mail():
    pass

当我向上述地址发送电子邮件时,日志中出现:

 2012-09-03 17:03:00.878 /_ah/mail/contact@appid.appspotmail.com 200 187ms 0kb  
 0.1.0.20 - - [03/Sep/2012:07:03:00 -0700] "POST /_ah/mail/contact@appid.appspotmail.com HTTP/1.1" 200 59 

如何阅读/解析邮件?

提前感谢您的任何回答或评论。

【问题讨论】:

  • 请不要进行无意义的编辑。
  • 为什么“毫无意义”?它没有害处。它只会让答案和问题看起来更清晰、更清晰,尤其是对于初学者。
  • 在编辑帮助部分它写道:“任何时候你觉得你可以使帖子更好,并且倾向于这样做。鼓励编辑!编辑的一些常见原因是:修复语法或拼写错误,在不更改帖子的情况下阐明帖子的含义”等。不鼓励仅使用“单个字符”/“微小”/“琐碎”的编辑。
  • And only "single character"/"tiny"/"trivial" edits - 这正是你在做什么。
  • 如果您认为该问题 (stackoverflow.com/questions/5137051/pdo-php-fetch-class) 在您将其回滚到初始版本后看起来更清晰、更清晰,那么我将不再为编辑而烦恼。(而且它不是“单字符”编辑:它改进了格式和拼写/语法)。

标签: google-app-engine bottle


【解决方案1】:

您应该能够使用 mail.InboundEmailMessage 解码 POST 正文,就像在 webapp.InboundMailHandler 中一样

from google.appengine.api import mail

@route('/_ah/mail/contact@appid.appspotmail.com', method = 'POST')
def receive_mail():
    message = mail.InboundEmailMessage(request.body)
    logging.info("received email from: %s" % message.sender)

【讨论】:

  • 非常感谢!有用! (顺便说一句,这是您的回答中的错字:缺少右双引号)
猜你喜欢
  • 2011-05-13
  • 1970-01-01
  • 2010-12-14
  • 2018-08-02
  • 2014-08-06
  • 1970-01-01
  • 1970-01-01
  • 2014-11-05
  • 2015-10-15
相关资源
最近更新 更多