email 8bit encoding
rurpy at yahoo.com
rurpy at yahoo.com
Thu Aug 1 11:20:34 EDT 2013
On 07/29/2013 02:52 PM, Antoon Pardon wrote:
> Op 29-07-13 01:41, rurpy at yahoo.com schreef:
>> How, using Python-3.3's email module, do I "flatten" (I think
>> that's the right term) a Message object to get utf-8 encoded
>> body with the headers:
>> Content-Type: text/plain; charset=UTF-8
>> Content-Transfer-Encoding: 8bit
>> when the message payload was set to a python (unicode) string?
>>
>
> I am just trying out some things for my self on python 3.2 so
> be sure to test this out but you could try the following.
>
> msg.set_charset('utf-8')
> msg['Content-Transfer-Encoding'] = '8bit'
You can do that but the problem occurs when you call
email.generator.flatten (or it is called on your behalf by
somthing like smtplib.send_message) with such a message.
flatten always assumes a 7bit encoding and uses the ascii
codec to encode the message resulting in a UnicodeEncode
exception when it hits an 8 bit character. So gymnastics
like W. Trevor King implemented are necessary.
More information about the Python-list
mailing list