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

Discussion in 'Python' started by Nico Grubert, Dec 8, 2006.

  1. Nico Grubert

    Nico Grubert Guest

    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 = ''
    mTo = ''
    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
    Nico Grubert, Dec 8, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Francesco
    Replies:
    1
    Views:
    517
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Dec 27, 2006
  2. Fredrik Lundh
    Replies:
    0
    Views:
    439
    Fredrik Lundh
    Dec 8, 2006
  3. Michiel Overtoom

    Re: Problem reading file with umlauts

    Michiel Overtoom, Jul 7, 2009, in forum: Python
    Replies:
    1
    Views:
    431
    Stefan Behnel
    Jul 7, 2009
  4. MRAB
    Replies:
    0
    Views:
    480
  5. Sholto Douglas
    Replies:
    0
    Views:
    439
    Sholto Douglas
    Jun 6, 2011
Loading...

Share This Page