Advertisement
Guest User

Untitled

a guest
Oct 5th, 2016
110
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. sender = 'ME@EXAMPLE.COM'
  12. targets = ['HE@EXAMPLE.COM', 'SHE@EXAMPLE.COM']
  13.  
  14. msg = MIMEMultipart()
  15. msg['Subject'] = 'I have a picture'
  16. msg['From'] = sender
  17. msg['To'] = ', '.join(targets)
  18.  
  19. txt = MIMEText('I just bought a new camera.')
  20. msg.attach(txt)
  21.  
  22. filepath = '/path/to/image/file'
  23. with open(filepath, 'rb') as f:
  24. img = MIMEImage(f.read())
  25.  
  26. img.add_header('Content-Disposition',
  27. 'attachment',
  28. filename=os.path.basename(filepath))
  29. msg.attach(img)
  30.  
  31. server = smtplib.SMTP_SSL(smtp_ssl_host, smtp_ssl_port)
  32. server.login(username, password)
  33. server.sendmail(sender, targets, msg.as_string())
  34. server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement