SHARE
TWEET

Untitled

a guest May 23rd, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = ''
  10. password = ''
  11. sender = 'mateuszw.gt@gmail.com'
  12. targets = ['patrykkotlowski@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 = 'tree.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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top