himanshu208

Untitled

Oct 23rd, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 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. from picamera import PiCamera
  7. from time import sleep
  8. from RPi import GPIO
  9.  
  10. button = 17
  11.  
  12. GPIO.setmode(GPIO.BCM)
  13. GPIO.setup(button, GPIO.IN, GPIO.PUD_UP)
  14.  
  15. def SendMail(ImgFileName):
  16. img_data = open(ImgFileName, 'rb').read()
  17. msg = MIMEMultipart()
  18. msg['Subject'] = 'Door Bell By Raspberry pi'
  19. msg['From'] = ''#put your email id here
  20. msg['To'] = 'himanshusaleria@gmail.com'# put receivers email id here
  21.  
  22. text = MIMEText("Door Bell Image")# text to be sent in mail
  23. msg.attach(text)
  24. image = MIMEImage(img_data, name=os.path.basename(ImgFileName))
  25. msg.attach(image)
  26.  
  27. s = smtplib.SMTP('smtp.gmail.com', 587)
  28. s.ehlo()
  29. s.starttls()
  30. s.ehlo()
  31. s.login("gmailid@gmail.com", "password")#gmail id and password
  32. s.sendmail("your email", "receivers email", msg.as_string())#put yours and receivers email here
  33. s.quit()
  34.  
  35.  
  36.  
  37.  
  38. with PiCamera() as camera:
  39. camera.rotation=180
  40. camera.start_preview()
  41. GPIO.wait_for_edge(button, GPIO.FALLING)
  42. filename = '/home/pi/Desktop/image.jpg'
  43. camera.capture(filename)
  44. SendMail(filename)
  45. camera.stop_preview()
Add Comment
Please, Sign In to add comment