Guest User

Untitled

a guest
Oct 5th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import os
  2. import smtplib
  3. from email.mime.text import MIMEText
  4. from email.mime.image import MIMEImage
  5. from email.mime.multipart import MIMEMultipart
  6.  
  7. smtp_ssl_host = 'smtp.gmail.com' # smtp.mail.yahoo.com
  8. smtp_ssl_port = 465
  9. username = 'USERNAME or EMAIL ADDRESS'
  10. password = 'PASSWORD'
  11.  
  12. msg = MIMEMultipart()
  13. msg['Subject'] = 'I have a picture'
  14. msg['From'] = sender
  15. msg['To'] = ', '.join(targets)
  16.  
  17. txt = MIMEText('I just bought a new camera.')
  18. msg.attach(txt)
  19.  
  20. filepath = '/path/to/image/file'
  21. with open(filepath, 'rb') as f:
  22. img = MIMEImage(f.read())
  23.  
  24. img.add_header('Content-Disposition',
  25. 'attachment',
  26. filename=os.path.basename(filepath))
  27. msg.attach(img)
  28.  
  29. server = smtplib.SMTP_SSL(smtp_ssl_host, smtp_ssl_port)
  30. server.login(username, password)
  31. server.sendmail(sender, targets, msg.as_string())
  32. server.quit()
Advertisement
Add Comment
Please, Sign In to add comment