brian, great idea for including a more full-fledged example in the docs. we'll take it under consideration. perhaps we can get *your* app working and perhaps take a snippet from there!
the reason you're getting the error is in the realm of Python (and not really App Engine). what you're trying to do is to create one long string made up of "Message body:" and the text body from the email message. the problem is that the InboundEmailMessage.bodies() method doesn't return a string. here, take a closer look at the docs: http://code.google.com/appengine/docs/python/mail/receivingmail.html under "Handling Incoming Email," it tells you that what you get back is a list/iterator of perhaps more than one email body. in order to fix your problem, you either have to just pull out the text for the first (and only message), or if there are more than one, to concatenate all the text bodies into your log entry. in other words, "text" should probably be called 'text_bodies'. then you can do something like: logging.info("%s: %s" % ('Message bodies', ''.join('msg %d: %s; ' % x for x in enumerate(text_bodies))) hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: [email protected] developer relations :: google app engine On Jan 5, 6:59 pm, Brian <[email protected]> wrote: > I am trying out the incoming email module, and am stumped. I do the > following: > > class LogSenderHandler(InboundMailHandler): > def receive(self, mail_message): > logging.info("Received a message from: " + mail_message.sender > + " to: " + mail_message.to) > text = mail_message.bodies(content_type='text/plain') > logging.info("Message body: " + text) > self.response.out.write('ok') > > I can fetch the to/from/subject fields, but when I try to read the > message body, I get the following error. Obviously I need to do > something else, but I can't find any documentation about this. It > would be nice if Google would publish a more complete sample app that > processes inbound email. If someone has an example they can post I'd > really appreciate it. I know it should not be that difficult. > > cannot concatenate 'str' and 'generator' objects > Traceback (most recent call last): > File "/base/python_lib/versions/1/google/appengine/ext/webapp/ > __init__.py", line 509, in __call__ > handler.post(*groups) > File "/base/python_lib/versions/1/google/appengine/ext/webapp/ > mail_handlers.py", line 58, in post > self.receive(mail.InboundEmailMessage(self.request.body)) > File "/base/data/home/apps/brians-book/1.338965862895371758/ > handle_email.py", line 33, in receive > logging.info("Message body: " + text) > TypeError: cannot concatenate 'str' and 'generator' objects
-- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
