Python's email module - problem with umlauts in some email clients

N

Nico Grubert

Hi there,

I wrote a short python script that sends an email using python's email
module and I am using Python 2.3.5.
The problem is, that umlauts are not displayed properly in some email
clients:

+ On a windows machine running thunderbird 1.0.2 umlauts are displayed
properly.
The email header contains "Content-type: text/plain; charset=utf-8"
so the email client's character encoding automatically switches to
"Unicode (UTF-8)"

+ On a solaris machine running thunderbird 1.5.0.8 and on a macintosh
machine running eudora umlauts are *not* displayed properly.
The email header does not contain any "Content-type". If I manually
switch the email client's character encoding to "Unicode (UTF-8)", the
umlauts are displayed properly. Therefore, I guess it has something to
do with the missing "Content-type: text/plain; charset=utf-8"
information in the email header.

Any idea why the "Content-type: text/plain; charset=utf-8" is missing?


Here is my script:

#------------------------------------------------------------------
# send email
from email.Header import Header
import email.Message
import email.Utils
import mimetypes
from smtplib import SMTP

host = 'mail.example.com'
mFrom = '(e-mail address removed)'
mTo = '(e-mail address removed)'
mSubj = u'f\xfcr'
mBody = u'f\xfcr foo bar'
mBody = mBody.encode('UTF-8')

mainMsg = email.Message.Message()

mainMsg['From'] = mFrom
mainMsg['To'] = mTo
mainMsg['Subject'] = mSubj
mainMsg.set_payload(mBody)

mainMsg['Date'] = email.Utils.formatdate(localtime=1)
mainMsg['Message-ID'] = email.Utils.make_msgid()
mainMsg['Mime-version'] = '1.0'
mainMsg['Content-type'] = 'text/plain; charset=utf-8'
mainMsg['Content-transfer-encoding'] = '8bit'
# 'quoted-printable' does not work either
# mainMsg['Content-Transfer-Encoding'] = 'quoted-printable'

s = SMTP(host)
s.sendmail(mFrom, [mTo], mainMsg.as_string())
s.close()
#------------------------------------------------------------------

Regards,
Nico
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top