Code in receive handler
class LogSenderHandler(InboundMailHandler):
def receive(self, mail_message):
logging.info("Received a message from: " + mail_message.sender)
#logging.info("Received a message from: " + mail_message.attachments)
logging.info("Received a message from: " + mail_message.date)
logging.info("Received a message from: " + mail_message.开发者_JAVA技巧subject)
report = DocFile()
report.doc_name = mail_message.subject
if mail_message.attachments is not None:
report.doc_file = mail_message.attachments
else:
report.doc_file = mail_message.bodies(content_type='text/plain')
report.put()
application = webapp.WSGIApplication([LogSenderHandler.mapping()], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
code in url.py
inbound_services:
- mail
handlers:
- url: /_ah/mail/.+
script: handle_incoming_email.py
error when i try to send a simple email from http://localhost:8080/_ah/admin/inboundmail
Message send failure
Traceback (most recent call last):
File "F:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__
handler.post(*groups)
File "F:\Program Files\Google\google_appengine\google\appengine\ext\webapp\mail_handlers.py", line 58, in post
self.receive(mail.InboundEmailMessage(self.request.body))
File "F:\Program Files\Google\google_appengine\google\appengine\api\mail.py", line 547, in __init__
self.update_from_mime_message(mime_message)
File "F:\Program Files\Google\google_appengine\google\appengine\api\mail.py", line 1081, in update_from_mime_message
mime_message = _parse_mime_message(mime_message)
File "F:\Program Files\Google\google_appengine\google\appengine\api\mail.py", line 232, in _parse_mime_message
return email.message_from_file(mime_message)
File "F:\Python25\lib\email\__init__.py", line 66, in message_from_file
return Parser(*args, **kws).parse(fp)
File "F:\Python25\lib\email\parser.py", line 68, in parse
data = fp.read(8192)
AttributeError: Message instance has no attribute 'read'
EDIT This error comes only on local machine and not on app engine
Do you have the latest version of the API? for the incoming mail function need to be the 1.2.6 or greatest.
Later i saw in google groups the "solution" I quote Joshua Smith
"I've found that you need to restart the local dev environment before
doing any inbound mail testing. Otherwise, you'll get that read error"
So every time that you change your code you MUST restart the server, even if only add white spaces (seriously)
精彩评论