block
block

Reputation: 95

Add Text to Mail Body with Python

I'm trying to modify a mail body on the fly. In my scenario I'm using python as a filter for postfix. I get the mail and can read every part. My goal is to remove the attachment (set_payload("")) and add a info to the body of the mail. For text/plain and text/html.

But if I use attach() to add a MIMEText I only can this for the root payload element...

import email
from email.mime.text import MIMEText

foo = MIMEText("www.foooo.de")
foo
<email.mime.text.MIMEText instance at 0x7f4d12491320>
msg.get_payload()[0].get_payload()[0].attach(foo)

Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/email/message.py", line 166, in attach self._payload.append(payload) AttributeError: 'str' object has no attribute 'append'

How can I add a line at the end of the plain and the html message?

Upvotes: 1

Views: 2888

Answers (1)

solusipse
solusipse

Reputation: 587

There is no append method in str. You can append text to string in that way:

string = 'foo'
string += 'bar'

Upvotes: 1

Related Questions