Sending unicode emails

3 views
Skip to first unread message

N. Rosencrantz

unread,
Jun 3, 2008, 9:52:07 PM6/3/08
to Google App Engine
How do you send unicode emails with google.appengine.api.mail ? I get
UnicodeException with foreign characters.
Thank you
Niklas

Daniel O'Brien

unread,
Jun 6, 2008, 6:22:04 PM6/6/08
to Google App Engine
Are you encountering the error in both production and the SDK app
server, and are you able to post a code snippet and the actual
traceback?

Thanks!

Daniel

On Jun 3, 6:52 pm, niklasr <nikla...@gmail.com> wrote:
> How do you send unicode emails with google.appengine.api.mail? I get

N. Rosencrantz

unread,
Jun 6, 2008, 10:02:29 PM6/6/08
to Google App Engine
Yes and yes. It's an issue reported
http://code.google.com/p/googleappengine/issues/detail?id=429&sort=-id&colspec=ID%20Type%20Status%20Priority%20Stars%20Owner%20Summary
Storing unicode works fine but then when I email uncode or take it
from the form an email it it's not working. The address is for example
http://www2.montao.com.br/market/ahFjbGFzc2lmaWVkc21hcmtldHIJCxICQWQYgAgM/vi
where there is a form which doesn't work with foreign characters that
are needed. Here's the code, maybe we can tell python to respect
unicode?
Thank you
class Recommend(webapp.RequestHandler):
def post(self, key):
im = db.get(db.Key(key))
if os.environ.get('HTTP_HOST'):
url = os.environ['HTTP_HOST']
else:
url = os.environ['SERVER_NAME']
email = self.request.POST['tip_email']
msg = self.request.POST['tip_msg']
name = self.request.POST['tip_name']
message = mail.EmailMessage(sender="nikl...@gmail.com",
subject=unicode("%s recommends %s" %
(name, im.title) ))
message.to = email
message.body = "%s %s/market/%s/vi" % (msg, url, key)
message.send()
logging.info("%s emailed %s" % (name, email) )
self.response.out.write("%s emailed %s" % (name, email))

N. Rosencrantz

unread,
Jun 7, 2008, 3:21:53 AM6/7/08
to Google App Engine, Alex Hultmark, Km, Otto Dandenell, Peder Linder, Holger Rosencrantz, Göran E. Larsson
The solution seems to be this:
if isinstance(msg, unicode):
msg = msg.encode('utf-8')
Regards,
Niklas

On 7 Juni, 04:02, niklasr <nikla...@gmail.com> wrote:
> Yes and yes. It's an issue reportedhttp://code.google.com/p/googleappengine/issues/detail?id=429&sort=-i...
> Storing unicode works fine but then when I email uncode or take it
> from the form an email it it's not working. The address is for examplehttp://www2.montao.com.br/market/ahFjbGFzc2lmaWVkc21hcmtldHIJCxICQWQY...
> where there is a form which doesn't work with foreign characters that
> are needed. Here's the code, maybe we can tell python to respect
> unicode?
> Thank you
> class Recommend(webapp.RequestHandler):
> def post(self, key):
> im = db.get(db.Key(key))
> if os.environ.get('HTTP_HOST'):
> url = os.environ['HTTP_HOST']
> else:
> url = os.environ['SERVER_NAME']
> email = self.request.POST['tip_email']
> msg = self.request.POST['tip_msg']
> name = self.request.POST['tip_name']
> message = mail.EmailMessage(sender="nikla...@gmail.com",
Reply all
Reply to author
Forward
0 new messages