From 5629d18df474edff6e5d9f4a6d62452be35184d3 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 27 Jan 2026 14:40:42 -0600 Subject: [PATCH] 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 --- backend/app/services/email_service.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/app/services/email_service.py b/backend/app/services/email_service.py index 435d8c4..b899036 100644 --- a/backend/app/services/email_service.py +++ b/backend/app/services/email_service.py @@ -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: