Making a spy camera using Raspberry PI and PIR sensor

Making spy cam is a very easy task for this u required the following things.
1. Raspberry pi
2.RaspCam
3.PIR sensor
4. A micro USB port to power your raspberry pi.
Image result for raspberry pi and camera

How it will work:
By using a PIR sensor we can trigger our camera so that if anyone is detected in PIR sensor the camera gets activated and it sends the pic to your Gmail account. Just copy the below code and upload this to your raspberry pi.
Before uploading this you must activate the camera module of raspberry pi and it must be connected to the active internet.
If you are using the terminal then use "sudo apt-get update" and then use "sudo apt-get upgrade"

copy the below code

from picamera import PiCamera
from time import sleep
import smtplib
import time
from datetime import datetime
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
import RPi.GPIO as GPIO
import time

toaddr = 'TO_EMAIL'
me = 'FROM_EMAIL'
Subject='security alert'

GPIO.setmode(GPIO.BCM)

P=PiCamera()
P.resolution= (1024,768)
P.start_preview()
   
GPIO.setup(23, GPIO.IN)
while True:
    if GPIO.input(23):
        print("Motion...")
        #camera warm-up time
        time.sleep(2)
        P.capture('movement.jpg')
        time.sleep(10)
        subject='Security allert!!'
        msg = MIMEMultipart()
        msg['Subject'] = subject
        msg['From'] = me
        msg['To'] = toaddr
       
        fp= open('movement.jpg','rb')
        img = MIMEImage(fp.read())
        fp.close()
        msg.attach(img)

        server = smtplib.SMTP('smtp.gmail.com',587)
        server.starttls()
        server.login(user = 'FROM_EMAIL',password='PASSWORD')
        server.send_message(msg)
        server.quit()
if u are facing any problem contact me.