Search code examples
exchange-serverexchangewebservicesewsjavaapi

How to validate credentials in EWS Java API


I am using EWSJavaAPI 1.1.5. I am trying to login with invalid credentials, but I don't get any exceptions.

Please advise how to detect and handle invalid login.

Here is my code:

String host = "myhost";
ExchangeService service = null;
try {
    service = new ExchangeService();
    ExchangeCredentials credentials = new WebCredentials("wrongemail",
        "wrongpass");
    service.setCredentials(credentials);
    service.setUrl(new java.net.URI("https://" + host
        + "/EWS/Exchange.asmx"));
} catch (Exception e) {
    e.printStackTrace();
}

Solution

  • Found it, i had to bind the service to a folder:

    Folder.bind(service, WellKnownFolderName.Inbox);
    

    and if the credentials are wrong, HttpErrorException is thrown.