How to Resolve: "The request failed. The remote server returned an error (401)”?
When connecting to Exchange services (especially via SMTP or API), you might encounter the following error:
“The request failed. The remote server returned an error: (401) Unauthorized.”
This typically occurs due to incorrect credentials, mismatched user identity, or using the wrong username format during authentication.
Common Cause
The 401 Unauthorized error indicates that the remote server is rejecting the authentication request. In SMTP scenarios, this often happens when:
- You use an incorrect username format
- The credentials are invalid or expired
- SMTP authentication is disabled for the mailbox
- The User Principal Name (UPN) doesn’t match the Primary SMTP Address
Correct Username Format for SMTP
When authenticating, always use the User Principal Name (UPN)—usually the same as the primary email address, but not always.
How to Verify the Correct UPN
Use the following PowerShell command in Exchange Management Shell:
Get-Mailbox -Identity "mailbox@server.com" | Select-Object UserPrincipalName, PrimarySmtpAddress
Use the value from UserPrincipalName as the username when connecting via SMTP.
How to Fix the Error
- Verify the UPN using the command above
- Ensure credentials are correct (no typos, not expired)
- Use UPN for login, not domain\username format
- Check if SMTP Auth is enabled (especially in Exchange Online)
You can run:
Get-CASMailbox -Identity "user@domain.com" | Select SmtpClientAuthenticationDisabled
Conclusion
The 401 Unauthorized error usually points to an issue with how you're authenticating to the SMTP or Exchange service. Always confirm the UPN and credentials are correct, and ensure SMTP authentication is enabled if required.




