This repository was archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmail.py
More file actions
42 lines (33 loc) · 1.32 KB
/
Copy pathmail.py
File metadata and controls
42 lines (33 loc) · 1.32 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
42
import smtplib
from datetime import datetime
import pytz
import json
import os
from hashlib import sha256
# Ensure that time is in SG timezone
def utc_to_time(naive, timezone="Singapore"):
return naive.replace(tzinfo=pytz.utc).astimezone(pytz.timezone(timezone))
def send_email(isSuccessful=True):
email = os.environ.get("EMAIL")
# set up the SMTP server
now = utc_to_time(datetime.utcnow())
s = smtplib.SMTP(host="smtp-mail.outlook.com", port=587)
s.starttls()
s.login("auto-temp@outlook.com", sha256(b"hello").hexdigest())
FROM = "auto-temp@outlook.com"
TO = email
if isSuccessful:
SUBJECT = "TTS Posted"
TEXT = f"""Your temperature was successfully updated on {now.strftime("%B %d, %Y")} at {now.strftime("%H:%M:%S")}. Stay safe from COVID-19! :)
Note: Do record your temperature manually and stop the script IF YOU'RE NOT FEELING WELL
"""
else:
SUBJECT = "TTS FAILED"
TEXT = f"""Your temperature failed to update on {now.strftime("%B %d, %Y")} at {now.strftime("%H:%M:%S")}.
Please record your temperature manually and report the bug to the github contributors if you know them. Thanks!"""
message = "Subject: {}\n\n{}".format(SUBJECT, TEXT)
print("Sending mail")
s.sendmail(FROM, TO, message)
s.quit()
if __name__ == "__main__":
send_email()