谷歌appengine接收电子邮件错误

时间:2013-06-13 16:03:04

标签: python google-app-engine email

我遇到了麻烦。我现在正在玩谷歌应用程序中接收电子邮件很长一段时间,但在我的应用程序中,日志只能得到这个:

0.1.0.20 - - [13/Jun/2013:08:42:23 -0700] "POST /_ah/mail/contact@myappid.appspotmail.com HTTP/1.1" 200 0 - - "myappid.appspot.com" ms=69 cpu_ms=0 cpm_usd=0.100008 app_engine_release=1.8.1 instance=00c61b117c2fb913155f167711d12979c818fd

我的邮件处理程序脚本应该是这样的:mailmain.py

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

class LogSenderHandler(InboundMailHandler):
    def receive(self, mail_message):
        tobesent = mail_message.subject
        logging.info("From: " + mail_message.sender)
        logging.info("To:" + mail_message.to)
        logging.info("Subject: " + mail_message.subject)
        logging.info("Date: " + mail_message.date)

app = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)

我的app.yaml是这样的:

application: myappid
version: 1
runtime: python27
api_version: 1
threadsafe: no

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /_ah/mail/contact@myappid.appsportmail.com
  script: mailmain.py 
  login: admin

- url: /.*
  script: mailmain.py

inbound_services:
- mail

我尝试过使用脚本,所以我有很多版本,有些版本以此结尾(如果这很重要),但实际上没有任何作用:

def main():
    app = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)
    run_wsgi_app(application)
if __name__ == "__main__":
    main()

我上传了一个favicon.ico。

将错误用了几个小时的谷歌搜索,没有任何效果。 在Stackoverflow上我找到了类似的错误消息解决方案,例如将recieve更正为receive,但这不是这里的情况。我也复制了其他解决方案,也来自GITHUB,所以我相信这个问题并不重复。

1 个答案:

答案 0 :(得分:3)

你混淆了CGI和WSGI。参见Python27入门。 文档:https://developers.google.com/appengine/docs/python/gettingstartedpython27/usingwebapp

Yaml更新:

application: myappid
version: 1
runtime: python27
api_version: 1
threadsafe: false

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /_ah/mail/contact@myappid.appsportmail.com
  script: mailmain.app
  login: admin

- url: /.*
  script: mailmain.app

inbound_services:
- mail

使用WSGI,您不需要run_wsgi_app。

关于CGI / WSGI的一些背景知识:http://blog.notdot.net/2011/10/Migrating-to-Python-2-7-part-1-Threadsafe