Exchange Web Service API and 401 unauthorized exception

断了今生、忘了曾经 提交于 2019-11-27 08:50:51

Try changing this:

 exchangeService.Credentials = new WebCredentials("user@domain", "pwd", "domain");

into this:

 exchangeService.Credentials = new WebCredentials("user", "pwd", "domain");

Sometime the Login credentials depends on how Exchange/Active Directory it's configured. It could be user@domain or domain\user

It took me a lot of time to find a solution for the same issue. In my case, I needed to add to the EWS Virtual Directory under the IIS site the list of allowed URL's. Go to the IIS management, click the EWS node, under the Default Web Site, then double-click the Request Filtering. Go to the URL tab, and on the right, click Allow URL. Enter the url's by which you will invoke the service, e.g. example.com/ews/ or server.example.com/ews/

In addition, related to similar issues, I needed to add all hosts (*) to the winrm trusted host (by default it had only the local IP listed).

HTH.

KSampath

This issue can cause the two way authentication provide by Microsoft office 365. Better create a app password and pass that instead of outlook password.

exchangeService.Credentials = new WebCredentials("email", "app-pwd");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!