Spaces:
Sleeping
Sleeping
Create notification_tool.py
Browse files- notification_tool.py +21 -0
notification_tool.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import smtplib
|
| 3 |
+
from email.message import EmailMessage
|
| 4 |
+
|
| 5 |
+
def send_email_reminder(email, task_name, deadline):
|
| 6 |
+
if not os.getenv("EMAIL_USER") or not os.getenv("EMAIL_PASSWORD"):
|
| 7 |
+
return "Email disabled: missing credentials"
|
| 8 |
+
|
| 9 |
+
msg = EmailMessage()
|
| 10 |
+
msg.set_content(f"⏰ Reminder: '{task_name}' is due on {deadline}")
|
| 11 |
+
msg["Subject"] = f"Deadline Reminder: {task_name}"
|
| 12 |
+
msg["From"] = os.getenv("EMAIL_USER")
|
| 13 |
+
msg["To"] = email
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
|
| 17 |
+
server.login(os.getenv("EMAIL_USER"), os.getenv("EMAIL_PASSWORD"))
|
| 18 |
+
server.send_message(msg)
|
| 19 |
+
return "✅ Email reminder sent!"
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"❌ Failed to send email: {str(e)}"
|