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}")