-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail2.py
28 lines (27 loc) · 973 Bytes
/
mail2.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
import requests, ssl, logging
def email_alart(door_state):
request_url = "https://api.mailgun.net/v3/mg.kansashunter.org/messages"
api_key = "key-e7a8070aaf3649a7494f8333edf04e1b"
fromaddr = "Safe Monitor <[email protected]>"
toaddr = ["[email protected]", "[email protected]"]
open_body = "The door to the safe has been OPENED!"
still_open_body = "The door to the safe has been OPENED \
for longer than the TIMEOUT!"
logging.captureWarnings(True)
if (door_state == "open"):
return requests.post(
request_url,
auth=("api", api_key),
data={"from": fromaddr,
"to": toaddr,
"subject": "SAFE ALART",
"text": open_body})
elif (door_state == "still_open"):
return requests.post(
request_url,
auth=("api", api_key),
data={"from": fromaddr,
"to": toaddr,
"subject": "SAFE ALART",
"text": still_open_body})
email_alart("still_open")