Take the 2-minute tour ×

Creating a web page that will connect to Exchange Web service and retrieve current user's Inbox items. The authentication needs to be integrated. We don't want anyone to login.

Configured IIS to do Windows Authentication and set below parameters in web.config.

This got it working but only if the website is called on the server where it's hosted. If I call the same exact URL on another workstation, I get (401) Unauthorized.

If the page correctly authenticates itself against exchange when executed on the host server, why doesn't the same thing work when the same page is called from client workstation? The windows/domain logon user id is the same in both cases. Below is how the code authenticates against Exchange.

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url = new Uri("https://hostname/EWS/Exchange.asmx");
service.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

Does anyone have an idea of what could be the culprit here? Thanks!

share|improve this question
possible duplicate of Exchange Web Service API and 401 unauthorized exception –  Shadow Wizard May 25 at 8:07

2 Answers 2

Try using:

service.Credentials = new WebCredentials("user", "passwordd", "domain");

It should work.

share|improve this answer

(401) Unauthorized error means you are not able to to log in, because of wrong username and password. you should try like this

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.Credentials = new NetworkCredential(username, password);
        service.TraceEnabled = true;

        ExportMIMEEmail(service, count); //call to export mails;

above code is working for me

share|improve this answer

Your Answer


