Email module
Bragi Baldursson
bragiba at simi.is
Thu May 16 07:30:38 EDT 2002
How do I create a message that contains both text and attachemnts.
In the example given on the module page it shows how to create a
message with a bunch of photos in it. I would like to additionally be
able to add some text to the message body.
msg = MIMEBase('multipart', 'mixed')
msg['Subject'] = 'Our family reunion'
msg['From'] = me
msg['To'] = COMMASPACE.join(family)
msg.preamble = 'Our family reunion'
# I WOULD LIKE TO ADD SOME PERSONAL NOTES INTO MESSAGE NOT AS A TEXT
FILE ATTACHMENT
# Guarantees the message ends in a newline
msg.epilogue = ''
# Assume we know that the image files are all in PNG format
for file in pngfiles:
# Open the files in binary mode. Let the MIMEIMage class
automatically
# guess the specific image type.
fp = open(file, 'rb')
img = MIMEImage(fp.read())
fp.close()
msg.attach(img)
More information about the Python-list
mailing list