The datastore entity gets created in the dev server.
However, when I deploy the app and send a mail, it receives the mail and runs the handler however no datastore entities are created, here is the handler code:
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.encodi开发者_运维技巧ng:
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()
In my log, I see these 3 logs for each mail:
logging.info("handled")
logging.info("mail received from "+mail_message.sender)
logging.info("Received a message from: " + mail_message.sender)
精彩评论