3 Jul
2003
3 Jul
'03
10:58 a.m.
On Wednesday 02 July 2003 21:34, george donnelly wrote:
I have a script that produces an email (in Spanish) when new content is published. I can get the body of the email to show up correctly (ie the accents etc render correctly) but the subject turns spanish characters into garbage.
SMTP message header has to be encoded specially if it contains non ascii characters. Subject has to be of the form: =?<enc>?b?<text>?= and text should be base64 encoded. Here is a simple script that will generate proper header value for a UTF-8 string: import base64 def encode_smtp_header (s): m = base64.encodestring (s.strip ()).strip () return "=?%s?%s?%s?=" % ('utf-8','b', m) Vladimir