Exchange Web Service - The remote server returned an error: (401) Unauthorized

Sam Cheng (Tata Consultancy Services Ltd) 26 Reputation points Microsoft Employee
2020-05-19T00:19:42.593+00:00

I am trying to connect to Exchange Web Service by using email and pwd:

var exchangeService = new ExchangeService()
{
//credentials.UserName
Credentials = new WebCredentials(credentials.EmailAddress, credentials.Password),
Timeout = 60000
};

        // Set the URL.
        exchangeService.Url = new Uri("https://computername.domain.contoso.com/EWS/Exchange.asmx");
        Logger.DebugFormat("Service URL: {0}", exchangeService.Url);

        return new EWSConnection()
        {
            Service = exchangeService,
            Router =
                new RecipientsMailboxManagerRouter(
                    new EWSMailFolder(Folder.Bind(exchangeService, WellKnownFolderName.Inbox), useConversationGuidOnly))
        };

And I got the remote server returned an error: (401) Unauthorized.
It used to be working fine but just last Friday, I got this issue. Can anyone help me please?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,959 questions
{count} vote

Accepted answer
  1. Manu Philip 16,971 Reputation points MVP
    2020-05-19T05:07:31.267+00:00

    Hello,

    Various exchange services can be tested with online testconnectivity tool from Microsoft. You may test the EWS connectivity as follows and see it works. If not adjust the code or server settings. If you need further support, please paste the test result here:

    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

    Thanks,
    Manu


2 additional answers

Sort by: Most helpful
  1. Sam Cheng (Tata Consultancy Services Ltd) 26 Reputation points Microsoft Employee
    2020-05-19T05:26:59.723+00:00

    Thank for the tool! I have been looking for something like this to test the connection.

    Here is the Exchange Web Services URL, https://outlook.office365.com/EWS/Exchange.asmx, that I am trying to access to.
    Unfortunately, I got the same issue.

    8356-ews-unauthorized.png


  2. Mohan Shendage 1 Reputation point
    2021-11-25T11:06:14.777+00:00

    By disabling MFA my issue was resolved, our system engineer moved our email account out of zone group.......Thanks a lot!!!