在谷歌应用引擎中接收邮件,处理程序工作,但不创建数据存储实体

时间:2011-03-20 10:23:30

标签: python google-app-engine

数据存储区实体在开发服务器中创建。

但是,当我部署应用程序并发送邮件时,它会收到邮件并运行处理程序,但是没有创建数据存储区实体,这里是处理程序代码:

  1 import logging, email
  2 import wsgiref.handlers
  3 from google.appengine.ext import webapp
  4 from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
  5 from google.appengine.ext.webapp.util import run_wsgi_app
  6 from google.appengine.ext import db
  7 from datetime import datetime
  8 from google.appengine.api import mail
  9 
 10 class mails(db.Model):
 11   fro = db.StringProperty()
 12   sub = db.StringProperty()
 13   time = db.DateTimeProperty()
 14   body = db.StringProperty()
 15   to = db.StringProperty()
 16   count = db.BooleanProperty(default=False) 
 17 
 18 class LogSenderHandler(InboundMailHandler):
 19   def receive(self, mail_message):
 20     logging.info("mail received from "+mail_message.sender)
 21     if mail_message.sender.split('@')[1] in ('bits-goa.ac.in', 'bits-pilani.ac.in'):
 22       store = mails()
 23       store.fro = mail_message.sender
 24 
 25       try:
 26         store.sub = mail_message.subject
 27       except:
 28         pass
 29 
 30       try:
 31         store.time = datetime.strptime(mail_message.date, '%a, %d %b %Y %H:%M:%S +0630')
 32       except:
 33         pass
 34       body = ""
 35       for b in mail_message.bodies("text/plain"):
 36         body_type, pl = b
 37         try:
 38           if pl.encoding:
 39             body = pl.payload.decode(pl.payload.encoding)
 40           else:
 41             body = pl.payload
 42         except Exception, e:
 43           logging.debug("Body: %s" % (pl))
 44       store.body = body
 45       store.to = mail_message.to
 46       if not db.Query(mails).filter('fro =', mail_message.sender).get():
 47         store.count = True
 48         sender_add = "thanks@bitsconv.appspotmail.com"
 49         subject = "Thank you"
 50         mail_body = "Your vote will be counted"
 51         mail.send_mail(sender_add, mail_message.sender, subject, body)
 52       store.put()
 53     logging.info("Received a message from: " + mail_message.sender)
 54 
 55 #application = webapp.WSGIApplication([LogSenderHandler.mapping()], debug=True)
 56 
 57 def main():
 58   logging.info("handled")
 59   application = webapp.WSGIApplication([LogSenderHandler.mapping()], debug=True)
 60   wsgiref.handlers.CGIHandler().run(application)
 61 
 62 if __name__ == '__main__':
 63     main()   

在我的日志中,我看到每封邮件的这3个日志:

logging.info("handled")
logging.info("mail received from "+mail_message.sender)
logging.info("Received a message from: " + mail_message.sender)

0 个答案:

没有答案