我在阅读有关Receiving Mail的教程。我的app.yaml文件更新的指示:在Google App Engine中接收邮件
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]
谁能向我解释我是如何处理该邮件?我如何访问电子邮件的内容?我的代码是
self.response.out.write(txtmsg)
in handle_incoming_email.py
但是不打印任何东西。
如果有人澄清如何接收电子邮件的作品,我将不胜感激。
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)
如果你能帮助我解决这些问题,我将不胜感激。
(I asked the same question在GAE组,但没有答案。)
这是logging.info(“从%s收到的电子邮件%”message.sender)的代码行,记录的东西? – systempuntoout 2010-11-20 15:24:38
是的;我不知道logging.info记录信息到日志控制台:)所以,代码似乎工作;现在我需要知道如何将电子邮件的内容写入数据存储区。谢谢! – Zeynel 2010-11-20 16:46:34