Chris Withers wrote:
> Chris Withers wrote:
>> print msg.as_string()
>>
>> MIME-Version: 1.0
>> Content-Type: text/plain; charset; charset="utf-8"
>                             ^^^^^^^
> Actually, even this isn't correct as you can see above...
> 
>> charset = Charset('utf-8')
>> msg = MIMEText('','plain',None)
>> msg.set_payload(u'Some text with chars that need encoding:\xa3',charset)

> Has no-one ever successfully generated a correctly formatted email with 
> email.MIMEText where the message includes non-ascii characters?!

What is the problem with encoding the message as utf-8 before setting 
the payload? That has always worked for me.


pl = u'Some text with chars that need encoding:\xa3'.encode('utf-8')
msg.set_payload(pl ,charset)

 From the docs:

"""
The payload is either a string in the case of simple message objects or 
a list of Message objects for MIME container documents (e.g. multipart/* 
and message/rfc822)
"""

Message objects are always encoded strings. I don't remember seeing that 
it should be possible to use a unicode string as a message.

The charset passed in set_payload(pl ,charset) is the charset the the 
string *is* encoded in. Not the charset it *should* be encoded in.

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to