Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.mime.application import MIMEApplication
- from os.path import basename
- import email
- import email.mime.application
- #plain text version
- text = "This is the plain text version."
- #html body
- html = """<html><p>This is some HTML</p></html>"""
- # Create message container - the correct MIME type is multipart/alternative.
- msg = MIMEMultipart('alternative')
- msg['Subject'] = "Deliverability Report"
- msg['From'] = "me@gmail.com"
- msg['To'] = "you@gmail.com"
- # Record the MIME types of both parts - text/plain and text/html
- part1 = MIMEText(text, 'plain')
- part2 = MIMEText(html, 'html')
- # create PDF attachment
- filename='graph.pdf'
- fp=open(filename,'rb')
- att = email.mime.application.MIMEApplication(fp.read(),_subtype="pdf")
- fp.close()
- att.add_header('Content-Disposition','attachment',filename=filename)
- # Attach parts into message container.
- msg.attach(att)
- msg.attach(part1)
- msg.attach(part2)
- # Send the message via local SMTP server.
- s = smtplib.SMTP()
- s.connect('smtp.webfaction.com')
- s.login('NAME','PASSWORD')
- s.sendmail(msg['From'], msg['To'], msg.as_string())
- s.quit()
- msg = MIMEMultipart('mixed')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement