-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAIL-Door camlock.py
38 lines (30 loc) · 1.07 KB
/
MAIL-Door camlock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import picamera, time
import smtplib, os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
camera = picamera.PiCamera()
camera.start_preview()
time.sleep(5) # hang for preview for 5 seconds
os.remove('snapshot.jpg')
camera.capture('snapshot.jpg')
camera.stop_preview()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
#Next, log in to the server
server.login("[email protected]", "PASSWORD")
#Send the mail
msg = MIMEMultipart()
msg['Subject'] = "New person is coming..."
msg['From'] = "[email protected]"
msg['To'] = ', '.join("[email protected]")
part = MIMEBase('application', "octet-stream")
part.set_payload(open("snapshot.jpg", "rb").read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="snapshot.jpg"')
body = "Open lock from here: http://localhost/servo.php"
msg.attach(MIMEText(body, 'plain'))
msg.attach(part)
server.sendmail("[email protected]", "[email protected]",msg.as_string())