我正在阅读有关的教程接收邮件 http://code.google.com/appengine/docs/python/mail/receivingmail.html。我按照指示更新了 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
并发送电子邮件至[email protected] /cdn-cgi/l/email-protection
谁能向我解释一下如何处理这封电子邮件?我如何访问电子邮件的内容?我有代码
self.response.out.write(txtmsg)
in handle_incoming_email.py
但这不会打印任何内容。
如果有人澄清接收电子邮件的工作原理,我将不胜感激。
例如,在这个问题中 https://stackoverflow.com/questions/3763630/match-email-sender-field-with-a-user-id-google-app-engine
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
我的处理程序hw.py
脚本?如果我这样做,我该把这条线放在哪里
application = webapp.WSGIApplication([
ReceiveEmail.mapping()
], debug=True)
如果您能帮助我解决这些问题,我将不胜感激。
(我问了同样的问题 http://groups.google.com/group/google-appengine/browse_thread/thread/e170a677bbfdb7ce?hl=en#在 GAE 组,但没有答案。)