[issue1556] Failure when calling __str__ for MIMEBase(message, rfc822) objects

Anthony Lenton report at bugs.python.org
Sat Jun 21 23:05:32 CEST 2008


Anthony Lenton <antoniolenton at gmail.com> added the comment:

I don't really think the MIMEBase class is supposed to be used like
this, or at all: it behaves more like a Multipart message in that it
expects to carry a list of MIMEBase objects as a payload (not a string!)
though it doesn't define a boundary by default.

You can carry on using the MIMEBase class, but changing the line that says:

    attachment.set_payload(file(filename).read( ))

for:

    attachment.set_payload([MIMEText(file(filename).read())])

I'd recommend you to use:

    attachment = Message()
    attachment.set_payload(file(filename).read())

or if you want a multipart message:

    attachment = MIMEMultipart()
    text = MIMEText(file(filename).read())
    attachment.attach(text)

----------
nosy: +elachuni

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1556>
_______________________________________


More information about the Python-bugs-list mailing list