【问题标题】:receive() method of receiving mail resulting in 405 Method Not Allowedreceive() 接收邮件的方法导致 405 Method Not Allowed
【发布时间】:2014-08-01 09:49:54
【问题描述】:

在我的应用中,每当我尝试接收我的应用的电子邮件并向 receive() 方法发送请求时,我都会收到错误 405 Method Not Allowed

通过 id string@appid.appspotmail.com 发送电子邮件可以正常工作,但接收到此 id 的电子邮件会导致此错误。

我这样配置我的应用程序

app.yaml

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

inbound_services:
- mail 

handlers:  
- url: /_ah/mail/.+
  script: incoming_mail.py
  login: admin

- url: /
  script: abc.py 

incoming_mail.py

import email
import logging
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler

class LogSenderHandler(InboundMailHandler):

    def receive(self,email):
        logging.info("Received a message from: %s" %   email.sender)


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

def main():
    run_wsgi_app(app)

if __name__ == "__main__":
    main()

每当我通过这个网址http://appid.appspot.com/_ah/mail/string@appid.appspotmail.com

我收到错误405 Method not allowed

完全卡住了。提前感谢您提供的任何帮助!

【问题讨论】:

    标签: python google-app-engine email


    【解决方案1】:

    GAE 不会存储您收到的邮件。您需要存储它并创建自己的代码来管理它。他们提到“/_ah/mail/address”来解释如何在 app.yaml 中处理它。如果向下滚动,您可以看到如何处理多个不同的处理程序。

    您收到“405 Method not allowed The method GET is not allowed for this resource.”,因为您的代码中没有 Get 处理程序。

    就我个人而言,我会将电子邮件存储在祖先密钥数据存储中(父母是它被发送到的人)并让另一个脚本句柄来管理它(即查看、回复、删除)。

    【讨论】:

    • 感谢您的回复。如果 gae 不存储邮件,那么我如何跟踪收到的所有邮件到应用程序?因为我在跟踪邮件时遇到错误,接收方法导致错误,然后我将如何获取应用程序的所有电子邮件。 PS 我在另一个处理程序中有一个 get 方法,我通过 app.yaml 路由其他模式。
    • 当调用 receive(self,email) 时,将邮件存储到数据存储中。然后你需要创建另一个页面来查看它。
    猜你喜欢
    • 1970-01-01
    • 2016-05-12
    • 2018-07-09
    • 2016-04-12
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    相关资源
    最近更新 更多