sending email with charset utf-8 but subject is not coded properly

  • Thread starter =?ISO-8859-2?Q?Grzegorz_=A6lusarek?=
  • Start date
?

=?ISO-8859-2?Q?Grzegorz_=A6lusarek?=

Hi all. I sending email using standard python modules smtplib, email,
coding email in utf but subject of message is not coded properly. In
subject i use my national characters (polish) and after send i get XX in
place these characters.
Here is the code

Message = email.message_from_string(pMessage)
Message.set_charset('utf-8')
Message['From'] = '(e-mail address removed)'
Message['To'] = '(e-mail address removed)'
SMTPServer=smtplib.SMTP(ConfigurationManager.SMTPServer)
SMTPServer.sendmail('(e-mail address removed)','(e-mail address removed)', Message.as_string())

Message looks like this:
Subject: Nowe has³o
\n
\n
Nowe email z haslem......

I looked how smtp serwer see my message and I notice that it looks like
content of the message is convert by BASE64 but not the subject. What
I'm doing wrong? can anyone tell me?
 
R

Rene Pijlman

Grzegorz ¦lusarek:
I sending email using standard python modules smtplib, email,
coding email in utf but subject of message is not coded properly. In
subject i use my national characters (polish) and after send i get XX in
place these characters.
Here is the code

Message = email.message_from_string(pMessage)
Message.set_charset('utf-8')
Message['From'] = '(e-mail address removed)'
Message['To'] = '(e-mail address removed)'
SMTPServer=smtplib.SMTP(ConfigurationManager.SMTPServer)
SMTPServer.sendmail('(e-mail address removed)','(e-mail address removed)', Message.as_string())

I see no subject in this code.

"If you want to include non-ASCII characters in your email headers, say in
the Subject: or To: fields, you should use the Header class and assign the
field in the Message object to an instance of Header instead of using a
string for the header value."
http://docs.python.org/lib/module-email.Header.html
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top