51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
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"""
|
|
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; color: #333;">
|
|
<h2 style="color: #2563eb;">Interview Scheduled</h2>
|
|
<p>Hi {candidate_name},</p>
|
|
<p>Your interview has been scheduled for <strong>{date}</strong> at <strong>{time}</strong>.</p>
|
|
<p><strong>Meeting Link:</strong> <a href="{meeting_link}">{meeting_link}</a></p>
|
|
{f'<p><strong>Notes:</strong> {notes}</p>' if notes else ''}
|
|
<br>
|
|
<p>Best regards,<br>HireAI Team</p>
|
|
</div>
|
|
"""
|
|
|
|
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
|