Netsight Blog

Cool stuff Netsight are up to in Zope and Plone

Avatar

Internationalised email headers in Python

written by Matthew Sital-Singh, on Jun 13, 2008 10:11:00 AM.

Here is how you create international characters in email headers. Useful if people have umlauts and accents in their name:

>>> from email.message import Message
>>> from email.header import Header
>>> msg = Message()
>>> h = Header('p\xf6stal', 'iso-8859-1')
>>> msg['Subject'] = h
>>> print msg.as_string()
Subject: =?iso-8859-1?q?p=F6stal?=

More info here:

http://docs.python.org/lib/module-email.header.html

Leave a Reply