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

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top