Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 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 = 'wnotest.test123'
  10. password = 'Test1234!'
  11. sender = 'wnotest.test123@gmail.com'
  12. targets = ['wnotest.test123@gmail.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 = 'C:/Projekty/bomba.jpg'
  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