"""Email service using Resend.""" import httpx from typing import Optional, List from app.core.config import settings class EmailService: RESEND_API = "https://api.resend.com/emails" @classmethod async def send( cls, to: List[str], subject: str, html: str, text: Optional[str] = None ) -> bool: if not settings.RESEND_API_KEY: return False async with httpx.AsyncClient() as client: try: response = await client.post( cls.RESEND_API, headers={ "Authorization": f"Bearer {settings.RESEND_API_KEY}", "Content-Type": "application/json" }, json={ "from": settings.EMAIL_FROM, "to": to, "subject": subject, "html": html, "text": text } ) return response.status_code == 200 except Exception: return False @classmethod async def send_welcome(cls, email: str, name: str, org_name: str): html = f"""
Hi {name},
You've been added to {org_name}.
JIRA AI Fixer automatically analyzes support issues and suggests code fixes using AI.
— The JIRA AI Fixer Team
Issue {issue_key} has been analyzed.
Confidence: {confidence:.0%}
{f'Pull Request: {pr_url}
' if pr_url else ''}Here's what happened in {org_name} this week:
Issues Analyzed: {stats.get('analyzed', 0)}
PRs Created: {stats.get('prs', 0)}
Avg Confidence: {stats.get('confidence', 0):.0%}