email.Message problem
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Wed Sep 3 23:11:45 EDT 2008
En Wed, 03 Sep 2008 07:36:30 -0300, Corrado Gioannini <gioco at nekhem.com>
escribi�:
> On Tue, Sep 02, 2008 at 04:50:15PM -0300, Gabriel Genellina wrote:
>> > messg = email.message.Message()
>>
>> Replace this line with:
>> messg = email.mime.multipart.MIMEMultipart()
>> *OR*
>> Set the Content-Type header to "multipart/mixed" *before* anything else.
>
> thanks Gabriel!
>
> i coudn't have thought that setting the header in a different order
> could affect the as_string method. i'll take a look at the code. :)
Yes. This is the offending sequence:
messg = email.message.Message()
messg.set_charset('ISO-8859-15')
messg["Content-type"] = "Multipart/mixed"
"Charset" is not a header by itself; it is an optional parameter of the
Content-Type header. When you call set_charset(), a default 'Content-Type:
text/plain; charset="ISO-8859-15"' header is added. Later, you *add* a new
Content-type header -- remember that the [] notation *appends* a new
header instead of replacing an existing one (yes, it is somewhat
confusing...)
Your message ends up being text/plain, not multiplart as intended.
It's better to be explicit and use the email.mime.multipart.MIMEMultipart
class.
--
Gabriel Genellina
More information about the Python-list
mailing list