I have the following code :
msgtxt = "é"
msg = MIMEText(msgtxt)
msg.set_charset('ISO-8859-1')
msg['Subject'] = "subject"
msg['From'] = "from@mail.com"
msg['To'] = "to@mail.com"
serv.sendmail("from@mail.com","to@mail.com", msg.as_string())
The e-mail arrive with é as its body instead of the expected é
I have tried :
msgtxt = "é".encode("ISO-8859-1")
msgtxt = u"é"
msgtxt = unicode("é", "ISO-8859-1")
all yield the same result.
How to make this work?
Any help is appreciated.
Thanks in advance, J.
Well, what’s the encoding of the source file containing this code? If it’s UTF-8, which is a good default choice, just writing the
éwill have given you the two-byte string'\xc3\xa9', which, when viewed as ISO-8859-1, looks likeé.If you want to use non-ASCII byte string literals in your source file without having to worry about what encoding the text editor is saving it as, use a string literal escape: