healthchat / modules /email_reminder.py
Prince012's picture
multimodal ai chatbot
03d8f07
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}")