How to handle intermittent email failures with MessagingException in FusionAuth?
-
We're experiencing intermittent email delivery failures in FusionAuth for password resets and user signups. The event logs show errors like:
Cause: jakarta.mail.MessagingException : Message: Exception reading responseOur SMTP provider logs confirm that some emails are getting through successfully, so the issue appears to be intermittent rather than a complete outage.
Questions:
- What could be causing these intermittent
MessagingExceptionerrors? - Does FusionAuth have a built-in retry mechanism for failed email sends?
- What remediation steps can we take to improve email reliability?
- What could be causing these intermittent
-
This
MessagingException: Exception reading responseerror is often related to network issues or SMTP timeout configuration. Here's how to address it:Check and Adjust SMTP Timeout Settings
The default SMTP timeout in FusionAuth is 2 seconds, which may be too short if your SMTP provider experiences occasional network slowness. You can increase the timeout by:
- Navigate to Tenants > [Your Tenant] > Edit > Email > Advanced
- In the Additional properties field, add or adjust these configuration values:
mail.smtp.timeout=5000 mail.smtp.connectiontimeout=5000This increases the timeout to 5 seconds. Adjust the value as needed based on your SMTP provider's typical response times. The Additional properties field can contain any Java mail property, and these values will override FusionAuth's defaults.
Email Retry Policy
FusionAuth does not have a built-in retry mechanism for failed email sends. FusionAuth connects directly to your configured SMTP server at the tenant level without using a local mail queue. If an email fails to send due to a connection issue or timeout, FusionAuth will not automatically retry it.
Additional Troubleshooting Steps
-
Enable SMTP Debug Logging: In your tenant's Email settings, enable the Debug enabled option. This will provide detailed SMTP transaction logs in the FusionAuth event log, which can help identify the root cause of intermittent failures.
-
Review Event Logs: Check System > Event Log for error events. FusionAuth always creates an event log entry of type "Error" when it cannot send an email.
-
Send Test Emails: Use the Send test email button in Tenants > [Your Tenant] > Email to verify your SMTP configuration under different conditions.
Implementing Your Own Retry Logic
To handle retries, you can set up a webhook-based solution:
- Configure a webhook for the
event-log.createevent - Monitor events delivered to your webhook endpoint
- When you detect a
MessagingExceptionevent, trigger an API call to the appropriate endpoint (e.g.,/api/user/forgot-passwordfor password reset emails) - Important: Implement retry limits in your script to avoid infinite loops with invalid email addresses
This approach gives you full control over retry logic, backoff strategies, and error handling for failed email deliveries.
Related Documentation
- Configure SMTP - SMTP Settings - Complete SMTP configuration guide
- Tenants - SMTP Settings Form Fields - Details on the Additional properties field and how to customize Java mail properties
- Troubleshooting Email - Comprehensive email troubleshooting guide
- Event Log Create Event - Documentation on the
event-log.createwebhook event for monitoring errors - Start Forgot Password Workflow API - API endpoint for triggering password reset emails programmatically
-
D dan has marked this topic as solved