dawit45 commited on
Commit
bb28605
·
verified ·
1 Parent(s): 4d3e829

Create utils/notifications.py

Browse files
Files changed (1) hide show
  1. utils/notifications.py +22 -0
utils/notifications.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import smtplib
3
+ from email.message import EmailMessage
4
+
5
+ SMTP_USER = os.getenv("EMAIL_SMTP_USER")
6
+ SMTP_PASS = os.getenv("EMAIL_SMTP_PASS")
7
+
8
+ def send_alert_email(to_email, subject, body):
9
+ if not SMTP_USER or not SMTP_PASS:
10
+ return False, "Missing SMTP credentials"
11
+ msg = EmailMessage()
12
+ msg.set_content(body)
13
+ msg['Subject'] = subject
14
+ msg['From'] = SMTP_USER
15
+ msg['To'] = to_email
16
+ try:
17
+ with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
18
+ smtp.login(SMTP_USER, SMTP_PASS)
19
+ smtp.send_message(msg)
20
+ return True, "Sent"
21
+ except Exception as e:
22
+ return False, str(e)