473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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 = 'a*********@example.com'
mTo = 'f******@example.com'
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
Dec 8 '06 #1
0 1605

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.