How to send a proper unicode encoded email using Python 2.7
Posted by tkopczuk on June 28, 2011While working on a Django Celery task to send thousands of emails in various languages I had a problem with sending accented letters. Web crossed the Unicode line a while ago – email has yet to follow.
I have recently seen many posts on sending unicode email from Python (i.e. on Twisted Matrix Blog), but the methods did not produce proper results.
This method works, even with SendGrid.
(unknown sender) Gmail problem
Cited example lacks proper encoding of the From: header. It results in Gmail describing the sender as (unknown sender) if you attempt to give sender a name. The trick lies in Unicode quoted printable encoding the name and not the email address. Especially not “< >” characters that mark the address.
Complete code to send an email:
This quick tip marks the beginning of our useful Django performance tips series.
Through this weblog members of our Django team will share their experience to help you get your Django pony prancing!
We – Blade Polska – specialize in delivering highly scalable web applications.
We choose Django, as with a bit of work it can be made blazingly fast, scalable and first of all – managable. And full of magic.
Follow us on Twitter!
Comments
Pingback: Email unicode | Mendocinophotos()
Pingback: Python and Twisted: making utf-8 html mail with message-id | TechwikiHow()