Spaces:
Sleeping
Sleeping
File size: 988 Bytes
03d8f07 |
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 |
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import os
from dotenv import load_dotenv
load_dotenv()
EMAIL = os.environ["EMAIL"]
PASSWORD = os.environ["PASSWORD"]
def send_reminder_email(to_email, med_name, med_time):
try:
msg = MIMEMultipart()
msg['From'] = EMAIL
msg['To'] = to_email
msg['Subject'] = f"β° Medication Reminder: {med_name}"
body = f"""Hello,
This is your reminder to take:
π§ͺ {med_name}
π At: {med_time}
Take care!
- Your Medical AI Chatbot
"""
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(EMAIL, PASSWORD)
server.sendmail(EMAIL, to_email, msg.as_string())
server.quit()
print(f"β
Email sent to {to_email}")
except Exception as e:
print(f"β Failed to send email to {to_email}: {e}")
|