How do i add body to email.mime.multipart.MIMEMultipart instance?

Justin Ezequiel justin.mailinglists at gmail.com
Thu Feb 5 04:46:25 EST 2009


On Feb 4, 2:48 pm, srinivasan srinivas <sri_anna... at yahoo.co.in>
wrote:
> Hi,
> Could someone tell me the way to add body to the instance email.mime.multipart.MIMEMultipart instance which has attachments?
>
> Thanks,

msg = MIMEMultipart()
msg.preamble = 'This is a multi-part message in MIME format.\n'
msg.epilogue = ''

body = MIMEMultipart('alternative')
body.attach(MIMEText(text))
body.attach(MIMEText(html, 'html'))

msg.attach(body)

attachment = Message()
attachment.add_header('Content-type', content_type,
                      name=basename)
attachment.add_header('Content-transfer-encoding', 'base64')
attachment.add_header('Content-Disposition', 'attachment',
                      filename=basename)
attachment.set_payload(b.getvalue())

msg.attach(attachment)

msg.add_header('Message-ID', generate_message_id(sender[1]))
msg.add_header('Date', strftime(DATEFORMAT, gmtime()))

msg.add_header('From', formataddr(sender))
msg.add_header('To', format_addresses(TOs))
msg.add_header('Cc', format_addresses(CCs))
msg.add_header('Subject', subj)




More information about the Python-list mailing list