Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. # send e-mail with python
  2. import smtplib
  3. from email.mime.multipart import MIMEMultipart
  4. from email.mime.text import MIMEText
  5. from email.mime.image import MIMEImage
  6.  
  7.  
  8. msg = MIMEMultipart()
  9. msg['Subject'] = 'RPi Python test'
  10. msg['From'] = 'raspberrypitm@gmail.com'
  11. msg['To'] = 'kennyjoris97@gmail.com'
  12. msg.preamble ='This is a multifart message in MIME format.'
  13.  
  14.  
  15. message = """This is a test of using Python on Raspberry Pi
  16. to send an email."""
  17. msg.attach(MIMEText(message))
  18.  
  19.  
  20. filename = 'RaspberryPI.jpg'
  21. with open(filename, 'rb') as f:
  22. img = MIMEImage(f.read())
  23. img.add_header('Content-Disposition', 'attachment', filename=filename)
  24. msg.attach(img)
  25.  
  26.  
  27. username = 'raspberrypitm@gmail.com'
  28. password = 'thomasmore'
  29. server = smtplib.SMTP('smtp.gmail.com:587')
  30. server.starttls()
  31. server.login(username,password)
  32. server.sendmail(msg['From'], msg['To'], msg.as_string())
  33. server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement