Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import smtplib
  2. from email.mime.multipart import MIMEMultipart
  3. from email.mime.text import MIMEText
  4. from email.mime.application import MIMEApplication
  5. from os.path import basename
  6. import email
  7. import email.mime.application
  8.  
  9. #plain text version
  10. text = "This is the plain text version."
  11.  
  12. #html body
  13. html = """<html><p>This is some HTML</p></html>"""
  14.  
  15. # Create message container - the correct MIME type is multipart/alternative.
  16. msg = MIMEMultipart('alternative')
  17. msg['Subject'] = "Deliverability Report"
  18. msg['From'] = "me@gmail.com"
  19. msg['To'] = "you@gmail.com"
  20.  
  21. # Record the MIME types of both parts - text/plain and text/html
  22. part1 = MIMEText(text, 'plain')
  23. part2 = MIMEText(html, 'html')
  24.  
  25. # create PDF attachment
  26. filename='graph.pdf'
  27. fp=open(filename,'rb')
  28. att = email.mime.application.MIMEApplication(fp.read(),_subtype="pdf")
  29. fp.close()
  30. att.add_header('Content-Disposition','attachment',filename=filename)
  31.  
  32. # Attach parts into message container.
  33. msg.attach(att)
  34. msg.attach(part1)
  35. msg.attach(part2)
  36.  
  37. # Send the message via local SMTP server.
  38. s = smtplib.SMTP()
  39. s.connect('smtp.webfaction.com')
  40. s.login('NAME','PASSWORD')
  41. s.sendmail(msg['From'], msg['To'], msg.as_string())
  42. s.quit()
  43.  
  44. msg = MIMEMultipart('mixed')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement