Advertisement
Guest User

Untitled

a guest
May 9th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # Enable less secure apps in Gmail
  2.  
  3. import os
  4. import smtplib
  5. import email
  6. import sys
  7. import picamera
  8. import time
  9. from datetime import datetime
  10. from email.mime.multipart import MIMEMultipart
  11. from email.mime.image import MIMEImage
  12. from email.mime.text import MIMEText
  13.  
  14. with picamera.PiCamera() as camera:
  15. camera.rotation = 180 # delete this or adjust .rotation to 90, 180, or 270 accordingly
  16. camera.resolution = (1024, 768) # adjust resolution accordingly
  17. camera.start_preview()
  18. time.sleep(2) # camera warm-up
  19. camera.capture("photo.jpg")
  20.  
  21. f_time = datetime.now().strftime("%A %B %d %Y @ %H:%M")
  22.  
  23. img_data = open("photo.jpg", "rb").read()
  24. msg = MIMEMultipart()
  25. msg["Subject"] = f_time
  26. msg["From"] = "yourAddress@gmail.com"
  27. msg["To"] = "toAddress@mail.com"
  28.  
  29. text = MIMEText("Here's my latest photo!")
  30. msg.attach(text)
  31. image = MIMEImage(img_data, name=os.path.basename("photo.jpg"))
  32. msg.attach(image)
  33.  
  34. s = smtplib.SMTP("smtp.gmail.com:587")
  35. s.starttls()
  36. s.login("yourGmailLogin","yourPassword")
  37. s.sendmail("yourAddress@gmail.com","toAddress@mail.com", msg.as_string())
  38. s.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement