Spaces:
Sleeping
Sleeping
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}") | |