import asyncio
from email.message import EmailMessage
from app.config import get_settings
import aiosmtplib
async def send_contact_email(name: str, email: str, subject: str, message: str) -> None:
"""
Send contact form email via SMTP.
Args:
name: Sender name
email: Sender email
subject: Email subject
message: Message body
Raises:
Exception: If email sending fails
"""
settings = get_settings()
msg = EmailMessage()
msg["From"] = settings.smtp_user
msg["To"] = settings.smtp_user # Send to self
msg["Subject"] = f"[Geekbrain Contact] {subject}"
body = f"""Name: {name}
Email: {email}
Subject: {subject}
Message:
{message}
"""
msg.set_content(body)
try:
async with aiosmtplib.SMTP(hostname=settings.smtp_host, port=settings.smtp_port, start_tls=True) as server:
await server.login(settings.smtp_user, settings.smtp_password)
await server.send_message(msg)
except Exception as e:
# In production, use proper logging
print(f"Email send error: {e}")
# Don't raise - allow contact submission to succeed even if email fails