import httpx import logging from config.settings import get_settings logger = logging.getLogger(__name__) settings = get_settings() FROM_EMAIL = "CodeNexus " async def send_email(to: str, subject: str, html: str) -> bool: """Send email via Resend. Returns True on success.""" try: async with httpx.AsyncClient(timeout=15.0) as client: response = await client.post( "https://api.resend.com/emails", headers={"Authorization": f"Bearer {settings.resend_api_key}", "Content-Type": "application/json"}, json={"from": FROM_EMAIL, "to": [to], "subject": subject, "html": html} ) if response.status_code not in (200, 201): logger.error(f"Resend error {response.status_code}: {response.text}") return False return True except Exception as e: logger.error(f"Email send failed: {e}") return False async def send_welcome_email(to: str, name: str) -> bool: return await send_email( to=to, subject="Welcome to CodeNexus! 🚀", html=f"""

Welcome to CodeNexus!

Hi {name}, your account is ready.

Start writing and analyzing code right now — it's completely free.

Open Editor →

CodeNexus — Where Code Meets Intelligence

""" ) async def send_support_notification_to_admin(admin_email: str, user_email: str, category: str, message: str) -> bool: return await send_email( to=admin_email, subject=f"[CodeNexus Support] New {category} ticket from {user_email}", html=f"""

New Support Ticket

From: {user_email}

Category: {category}

Message:

{message}
View in Admin Panel →
""" ) async def send_support_confirmation_to_user(to: str, category: str) -> bool: return await send_email( to=to, subject="We received your support request — CodeNexus", html=f"""

We got your message!

Thanks for reaching out about {category}.

Our team will review your request and get back to you as soon as possible.

CodeNexus — Where Code Meets Intelligence

""" ) async def send_ticket_reply_to_user(to: str, reply: str) -> bool: return await send_email( to=to, subject="Reply to your CodeNexus support ticket", html=f"""

Support Reply

{reply}

CodeNexus Support Team

""" )