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. Any suggestions on where I can look for a solution? Here is the relevant part of the script: mMsg = "To:" + item.email + "\n" mMsg = mMsg + "From: me@example.com\n" mMsg = mMsg + "Mime-Version: 1.0\n" mMsg = mMsg + "Content-Type: text/plain; charset=utf-8\n\n" mMsg = mMsg + "FECHA: " + contentObject.Date() + "\n" mMsg = mMsg + "FUENTE: example \n\n" mMsg = mMsg + "RESUMEN: \n" mMsg = mMsg + contentObject.Description() + "\n\n" mMsg = mMsg + "TEXTO COMPLETO: " + contentObject.absolute_url() + "\n\n" mMsg = mMsg + "Mandar este articulo a un amigo: \n" mMsg = mMsg + contentObject.absolute_url() + "/portal_form/sendto_form\n\n" mMsg = mMsg + "Dejar de recibir alertas: http://example.com/portal_form/personalize_form\n\n" mSubj = "ALERTA:" + contentObject.Title() mailhost.send(mMsg, subject=mSubj, encode='quoted-printable') if i set the charset to iso-8859-1 then the body is screwed up as well. tia <--> george donnelly - http://www.zettai.net/ - "Quality Zope Hosting" Zope Hosting - Dynamic Website Design - Search Engine Promotion Yahoo, AIM: zettainet - MSN: zettainet@hotmail.com - ICQ: 51907738
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
[Vladimir Petrovic wrote (vladap@criticalpublics.com) on 7/3/03 10:58 AM]
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:
thanks for your suggestion and the script. I ended up doing it this way: ------ from email.Header import Header ...... esSubject = Header(contentObject.Title(), 'utf-8') essString = str(esSubject) ........ mSubj = essString mailhost.send(mMsg, subject=mSubj, encode='quoted-printable') ------ <--> george donnelly - http://www.zettai.net/ - "Quality Zope Hosting" Zope Hosting - Dynamic Website Design - Search Engine Promotion Yahoo, AIM: zettainet - MSN: zettainet@hotmail.com - ICQ: 51907738
participants (2)
-
george donnelly -
Vladimir Petrovic