EWS sometimes makes Error 401 Unauthorized exception

Jean-Michel Troy 20 Reputation points
2024-09-11T08:59:00.52+00:00

Hi,

I'm working on an api with exchange web service (ews) to handle new accounts and activation emails for a website.

It's deployed and it works but not all the time !

Sometimes, can be many times per week, i have this exception

StackTrace:

at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute() at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalFindFolders(IEnumerable1 parentFolderIds, SearchFilter searchFilter, FolderView view, ServiceErrorHandling errorHandlingMode) at Microsoft.Exchange.WebServices.Data.ExchangeService.FindFolders(FolderId parentFolderId, FolderView view)

Message:

The request failed. The remote server returned an error: (401) Unauthorized.

Then my customers are stucked without the activation link.

Can anyone help me understand how to avoid this exception that seems random for me ?

Regards,

Jean-Michel

Exchange Server
Exchange Server
A family of Microsoft client/server messaging and collaboration software.
1,448 questions
0 comments No comments
{count} votes

Accepted answer
  1. Mike Hu-MSFT 4,145 Reputation points Microsoft External Staff
    2024-09-12T09:10:34.45+00:00

    Hi,

    Welcome to the Microsoft Q&A platform!

    You can use online testconnectivity tool to test Exchange services.

    Follow the steps:

    1. Open https://testconnectivity.microsoft.com.
    2. Select Office 365 or Exchange Server as per your setup.
    3. Select Service Account Access and perform Test. Use the same parameters you use in code

    In addition, check if MFA or SSO is enabled for the mailbox you try to test. If so, disable those features and try a test

    Please feel free to contact me for any updates. And if this helps, don't forget to mark it as an answer!

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jean-Michel Troy 20 Reputation points
    2024-09-12T13:42:43.99+00:00

    Well this site looks usefull to test the services, i'll try to understand more with that.

    Thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.