import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from typing import Optional

# Set up your SMTP server settings
SMTP_SERVER = "smtp.gmail.com"  # Example: for Gmail
SMTP_PORT = 587
SENDER_EMAIL = "youremail@gmail.com"  # Replace with your email
SENDER_PASSWORD = "yourpassword"  # Replace with your email password or an app-specific password
SUBJECT = "Password Reset Request"

def send_email(recipient_email: str, subject: str, body: str) -> bool:
    """Send an email to the recipient."""
    try:
        # Set up the MIME (Multipurpose Internet Mail Extensions)
        msg = MIMEMultipart()
        msg["From"] = SENDER_EMAIL
        msg["To"] = recipient_email
        msg["Subject"] = subject

        # Attach the body with the msg instance
        msg.attach(MIMEText(body, "plain"))

        # Establish connection to the server and send email
        with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
            server.starttls()  # Use TLS (Transport Layer Security)
            server.login(SENDER_EMAIL, SENDER_PASSWORD)
            server.sendmail(SENDER_EMAIL, recipient_email, msg.as_string())

        return True
    except Exception as e:
        print(f"Failed to send email: {e}")
        return False