"""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"""

Welcome to JIRA AI Fixer! 🤖

Hi {name},

You've been added to {org_name}.

JIRA AI Fixer automatically analyzes support issues and suggests code fixes using AI.

Get Started

— The JIRA AI Fixer Team

""" await cls.send([email], f"Welcome to {org_name} on JIRA AI Fixer", html) @classmethod async def send_analysis_complete(cls, email: str, issue_key: str, confidence: float, pr_url: Optional[str]): html = f"""

Analysis Complete ✅

Issue {issue_key} has been analyzed.

Confidence: {confidence:.0%}

{f'

Pull Request: {pr_url}

' if pr_url else ''}
View Details
""" await cls.send([email], f"Analysis Complete: {issue_key}", html) @classmethod async def send_weekly_digest(cls, email: str, org_name: str, stats: dict): html = f"""

Weekly Digest 📊

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%}

View Full Report
""" await cls.send([email], f"Weekly Digest: {org_name}", html)