Advertisement
Guest User

Untitled

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