Skip to content

[PM-37651] Handle SocketException in admin login when mail server DNS fails#7654

Open
singhvishalkr wants to merge 1 commit into
bitwarden:mainfrom
singhvishalkr:fix/admin-login-smtp-error-handling
Open

[PM-37651] Handle SocketException in admin login when mail server DNS fails#7654
singhvishalkr wants to merge 1 commit into
bitwarden:mainfrom
singhvishalkr:fix/admin-login-smtp-error-handling

Conversation

@singhvishalkr
Copy link
Copy Markdown

🎟️ Tracking

Fixes #6792

📔 Objective

After a server migration, the mail server hostname in my self-hosted Bitwarden changed. When I tried to access the admin panel at /admin/, entering my email resulted in a redirect to /login/ with a 404 error instead of any useful feedback.

Looking at the logs, a SocketException with "Name does not resolve" was being thrown from MailKit when it tried to connect to the non-existent SMTP host. This exception propagated all the way up from PasswordlessSignInAsync through LoginController.Index, eventually hitting the error handler in an unexpected way.

The fix wraps the passwordless sign-in call in a try-catch for SocketException, logs the error for debugging, and redirects back to the login page with a clear message: "There was a problem sending the login email. Please check your mail server configuration."

This way, admins with misconfigured mail servers get actionable feedback instead of a cryptic 404.

When the SMTP server hostname cannot be resolved, PasswordlessSignInAsync
throws a SocketException from MailKit. Previously this propagated unhandled,
causing a confusing 404 error page.

Now the controller catches SocketException, logs the error for debugging,
and redirects to the login page with a clear message asking the user to
check their mail server configuration.

Co-authored-by: Cursor <cursoragent@cursor.com>
@singhvishalkr singhvishalkr requested a review from a team as a code owner May 16, 2026 08:52
@bitwarden-bot
Copy link
Copy Markdown
Collaborator

Thank you for your contribution! We've added this to our internal tracking system for review.
ID: PM-37651
Link: https://bitwarden.atlassian.net/browse/PM-37651

Details on our contribution process can be found here: https://contributing.bitwarden.com/contributing/pull-requests/community-pr-process.

@bitwarden-bot bitwarden-bot changed the title Handle SocketException in admin login when mail server DNS fails [PM-37651] Handle SocketException in admin login when mail server DNS fails May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected behaviour when mailserver DNS name does not exist

2 participants