Fix email service crash when Mailgun not configured

Add validation to check MAILGUN_API_URL has a valid protocol prefix
and MAILGUN_API_KEY is set before attempting to make HTTP request.
Returns False gracefully with warning log instead of crashing with
httpx.UnsupportedProtocol error.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
michael 2026-01-27 14:40:42 -06:00
parent c7228c95a2
commit 5629d18df4

View file

@ -24,6 +24,17 @@ class EmailService:
Returns:
True if email was sent successfully, False otherwise
"""
# Validate Mailgun configuration
if not settings.MAILGUN_API_URL or not settings.MAILGUN_API_URL.startswith(
("http://", "https://")
):
print("Warning: MAILGUN_API_URL not configured or missing protocol")
return False
if not settings.MAILGUN_API_KEY:
print("Warning: MAILGUN_API_KEY not configured")
return False
body = f"From: {user_name or 'Anonymous'}\nEmail: {user_email or 'Not provided'}\n\n{message}"
async with httpx.AsyncClient() as client: