import logging from fastapi_mail import FastMail, MessageSchema, ConnectionConfig, MessageType from pydantic import EmailStr from app.config import get_settings settings = get_settings() conf = ConnectionConfig( MAIL_USERNAME=settings.mail_username, MAIL_PASSWORD=settings.mail_password, MAIL_FROM=settings.mail_from, MAIL_PORT=settings.mail_port, MAIL_SERVER=settings.mail_server, MAIL_STARTTLS=settings.mail_tls, MAIL_SSL_TLS=settings.mail_ssl, USE_CREDENTIALS=True, VALIDATE_CERTS=True ) async def send_interview_email(candidate_email: EmailStr, candidate_name: str, date: str, time: str, meeting_link: str, notes: str): # Only try to send if credentials are provided if not settings.mail_username or not settings.mail_password: logging.warning("Email credentials not configured. Skipping interview email sending.") return False html = f"""

Interview Scheduled

Hi {candidate_name},

Your interview has been scheduled for {date} at {time}.

Meeting Link: {meeting_link}

{f'

Notes: {notes}

' if notes else ''}

Best regards,
HireAI Team

""" message = MessageSchema( subject="Interview Invitation - HireAI", recipients=[candidate_email], body=html, subtype=MessageType.html ) fm = FastMail(conf) try: await fm.send_message(message) return True except Exception as e: logging.error(f"Failed to send email: {e}") return False