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

  • Thread starter srinivasan srinivas
  • Start date
S

srinivasan srinivas

Hi,
Could someone tell me the way to add body to the instance email.mime.multipart.MIMEMultipart instance which has attachments?

Thanks,
Srini


Bollywood news, movie reviews, film trailers and more! Go to http://in.movies.yahoo.com/
 
J

Justin Ezequiel

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top