-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
41 lines (30 loc) · 934 Bytes
/
utils.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
39
40
41
import os
import smtplib
import ssl
from database import db
from dotenv import load_dotenv
import pytz
from models import *
load_dotenv()
EMAIL_ADDRESS = os.environ["EMAIL_ADDRESS"]
def is_past_due():
config = Config.query.first()
return timezone("US/Eastern").localize(config.due_date) < datetime.now(
tz=pytz.timezone("US/Eastern")
)
def send_email(to_email, message, sender_pw):
port = 587
smtp_server = "smtp-mail.outlook.com"
sender_email = EMAIL_ADDRESS
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.starttls(context=context)
server.login(sender_email, sender_pw)
server.sendmail(sender_email, to_email, message.strip())
def log_email(users, email_type):
for user in users:
log = EmailLog()
log.user_id = user.id
log.email_type = email_type
db.add(log)
db.commit()