tipsywacky
tipsywacky

Reputation: 3464

google app engine python mail api changing to utf-8 for other language?

body = """
Welcome %s,
Congratulations, you have just joined us.

Start using our site by click the link below:
%s

We hope that you enjoy!

Team.

恭喜妳/你已成為會員。

%s

希望妳能享受使用!

""".encode('utf-8') % (username, request_url, request_url)


mail.send_mail(sender=sender_address, to=email_address, subject=subject, body=body)

Okay here is what I have so far and it doesn't work. What can I do to encode utf-8 to mail api and make it works for using more than one language in the one email?

Thanks in advance.

Upvotes: 0

Views: 210

Answers (2)

tipsywacky
tipsywacky

Reputation: 3464

I figured out how to do it.

One way I found is to send mail through html.

ActivationEmailMessage.html = u"""
            <html><head></head><body>
            xxxxxx
            </body></html>
            """.encode('ascii', 'xmlcharrefreplace')

ActivationEmailMessage.send()

Upvotes: 1

voscausa
voscausa

Reputation: 11706

.encode('utf-8') makes binary out of the string. You have to use .decode('utf-8') See: http://blog.notdot.net/2010/07/Getting-unicode-right-in-Python and also http://docs.python.org/2/howto/unicode.html

Upvotes: 2

Related Questions