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:
parent
c7228c95a2
commit
5629d18df4
1 changed files with 11 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue