views:

244

answers:

1

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.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/%5Fah/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

A: 

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)

Kristian Damian
yes , its the latest version and i have done multiple re-sstarts, it works alright in production
dhaval
I test your code, and when i modify it the sources and the error appears, then when restart the server and works fine.
Kristian Damian
Thanx Kristian, I have also posted the same at http://groups.google.com/group/google-appengine-python/browse_thread/thread/2b8b8f652fc3a98a/1e7ed89c158cdd75#1e7ed89c158cdd75 and the issue is observed by others too. Are you saying that you dont get read error when you restart server and you are able to obtain the email?
dhaval
Yes, i write the code and i get the error, then i restart the server and works fine, but next i add a single withe space in the code and the error came againBefore[IMG]http://i48.tinypic.com/i74yea.png[/IMG]After[IMG]http://i46.tinypic.com/2cqb12o.png[/IMG]
Kristian Damian
here's the pastebin from the code http://pastebin.com/m7dbbf8a2and from the yaml filehttp://pastebin.com/d6de03ba9
Kristian Damian