我正在阅读关于
Receiving Mail
. 我按照说明更新了app.yaml文件:
application: hello-1-world
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: static/images/favicon.ico
- url: /_ah/mail/.+
script: handle_incoming_email.py
login: admin
- url: /.*
script: hw.py
inbound_services:
- mail
创造了一个
handle_incoming_email.py
import cgi
import os
import logging
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import mail
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
class ReceiveEmail(InboundMailHandler):
def receive(self,message):
logging.info("Received email from %s" % message.sender)
plaintext = message.bodies(content_type='text/plain')
for text in plaintext:
txtmsg = ""
txtmsg = text[1].decode()
logging.info("Body is %s" % txtmsg)
self.response.out.write(txtmsg)
application = webapp.WSGIApplication([
ReceiveEmail.mapping()
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
我也有
hw.py
我以前练习发邮件。那是有用的。
现在我去
http://localhost:8081/_ah/admin/inboundmail
并发送电子邮件至
help@hello-1-world.appspotmail.com
有人能告诉我如何处理这封邮件吗?如何访问电子邮件的内容?我有密码
self.response.out.write(txtmsg)
在里面
处理接收的电子邮件.py
但这并不能印出任何东西。
如果有人能澄清接收电子邮件的工作原理,我将不胜感激。
例如,
in this question
class MailHandler (InboundMailHandler):
def receive(self, message):
sender = message.sender
user_account = db.GqlQuery("SELECT * FROM Task WHERE user = :1", sender).fetch(5)
据我所知
sender
是发件人的电子邮件。所以,在我的例子中,我如何访问发件人的电子邮件地址。
另外,为什么我需要一个单独的脚本来处理传入邮件?为什么我不能把
ReceiveEmail
我的处理器
H.Py
脚本?如果我这样做,我该把线放在哪里
application = webapp.WSGIApplication([
ReceiveEmail.mapping()
], debug=True)
如果你能帮我解答这些问题,我将不胜感激。
(
I asked the same question
但没有答案。)