How to create a multipart / mime message with the correct CRLF in Python?

I need to create a multipart / mime message to send as a response to an HTTP request, but I find an error or restriction in the Python email batch. *.

The problem is that using Python 2.6, the call message.as_string()below generates a line with \ n, and CRLF at the end of the line:

message = MIMEMultipart()
for image in images:
    f = image.open('rb')
    img = MIMEImage(f.read(), _encoder=encode_7or8bit)
    message.attach(img)


message.as_string()

There seems to be no way to convince him to use the (MIME standard) CRLF. The Generator class, which seems to have to do this, does not.

What have other people done to get around this?

+5
source share
2 answers

This was a bug in Python, which is now fixed: http://hg.python.org/lookup/r85811

MIME , , .

+3

message.as_string().replace('\n', '\r\n')

? Inelegant, ( Python).

+2

All Articles