Skip to content

MIMEText instead of MIMEBase should be better for XML: why doesn't the encoding work? #1

@bartkl

Description

@bartkl

Ideally:

message_part = MIMEText(message, 'xml', 'utf8')

This should imply charset: UTF8 and the appropriate value for Content-Encoding-Type:

Unless the _charset parameter is explicitly set to None, the MIMEText object created will have both a Content-Type header with a charset parameter, and a Content-Transfer-Encoding header.

(https://docs.python.org/2.7/library/email.mime.html)

For some reason though, even the most trivial of strings get encoded in base64, and the charset parameter is not set.

So, for now I'm doing it manually:

message_part = MIMEBase('text', 'xml')
message_part.set_charset('utf8')
message.replace_header('Content-Transfer-Encoding', '8bit')
message_part.set_payload(message)

No big deal, but I really don't understand why the first code example doesn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementCode needs improvement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions