-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlert-Send_Information_Using_Mail.py
More file actions
41 lines (31 loc) · 1.25 KB
/
Alert-Send_Information_Using_Mail.py
File metadata and controls
41 lines (31 loc) · 1.25 KB
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
39
40
41
import time
import serial
import smtplib
import ssl
from email.message import EmailMessage
subject = "Security Alert!!!!!"
body = "თქვენს სახლში შემოჭრა დაფიქსირდა!!!"
sender_email = "tskhi2020@agruni.edu.ge"
receiver_email = "tskhi2020@agruni.edu.ge"
password = input("შეივანეთ ელ. ფოსტის პაროლი: ")
message = EmailMessage()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = subject
html = f"თქვენს სახლში შემოჭრა დაფიქსირდა!!!"
message.add_alternative(html, subtype="html")
context = ssl.create_default_context()
print("Sending Email!")
arduino_data = serial.Serial('com5', 9600)
time.sleep(1)
while True:
while arduino_data.inWaiting() == 0:
pass
data_packet = arduino_data.readline()
data_packet = str(data_packet, 'utf-8')
data_packet = data_packet.strip('\r\n')
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message.as_string())
print("Success")
print(data_packet)