modcomms/backend/app/services/email_service.py
michael e2fd9549f7 Add support email functionality via Mailgun
Backend:
- Add email_service.py with Mailgun API integration
- Add SupportEmailRequest schema for email endpoint
- Add Mailgun config settings (API URL, key, from address, support email)
- Update .env.example with Mailgun configuration variables

Frontend:
- Update Login.tsx SupportModal to send emails via /api/support/email
- Update Profile.tsx question form to send emails via apiService
- Add loading states, success/error feedback, and auto-close on success

The support forms on both the login page and profile page now actually
send emails to the support team instead of just showing alerts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 07:03:11 -06:00

43 lines
1.3 KiB
Python

"""Email service for sending support emails via Mailgun."""
import httpx
from app.config import settings
class EmailService:
"""Service for sending emails via Mailgun API."""
async def send_support_email(
self,
message: str,
subject: str,
user_name: str | None = None,
user_email: str | None = None,
) -> bool:
"""Send a support email via Mailgun API.
Args:
message: The message body
subject: Email subject line
user_name: Optional name of the user submitting
user_email: Optional email of the user submitting
Returns:
True if email was sent successfully, False otherwise
"""
body = f"From: {user_name or 'Anonymous'}\nEmail: {user_email or 'Not provided'}\n\n{message}"
async with httpx.AsyncClient() as client:
response = await client.post(
settings.MAILGUN_API_URL,
auth=("api", settings.MAILGUN_API_KEY),
data={
"from": settings.MAILGUN_FROM,
"to": settings.SUPPORT_EMAIL,
"subject": subject,
"text": body,
},
)
return response.status_code == 200
email_service = EmailService()