OfficeDev / ews-java-api

A java client library to access Exchange web services. The API works against Office 365 Exchange Online as well as on premises Exchange.
MIT License
868 stars 559 forks source link

ews-java-api cannot initialize ExchangeService #749

Open pipibilibili opened 2 years ago

pipibilibili commented 2 years ago

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); ExchangeCredentials credentials = new WebCredentials("xxxx@163.com", "xxxxx"); service.setCredentials(credentials); service.autodiscoverUrl("xxxx@163.com");

Exception in thread "main" microsoft.exchange.webservices.data.autodiscover.exception.AutodiscoverLocalException: The Autodiscover service couldn't be located. at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.internalGetLegacyUserSettings(AutodiscoverService.java:742) at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.getLegacyUserSettings(AutodiscoverService.java:521) at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.internalGetLegacyUserSettings(AutodiscoverService.java:959) at microsoft.exchange.webservices.data.autodiscover.AutodiscoverService.getUserSettings(AutodiscoverService.java:1846) at microsoft.exchange.webservices.data.core.ExchangeService.getAutodiscoverUrl(ExchangeService.java:3615) at microsoft.exchange.webservices.data.core.ExchangeService.autodiscoverUrl(ExchangeService.java:3572) at microsoft.exchange.webservices.data.core.ExchangeService.autodiscoverUrl(ExchangeService.java:3522) at EwsTest.main(EwsTest.java:29)

ThangLeQuoc commented 2 years ago

Possibly your credential initialization is wrong, did you try the alternative contructor with domain?

ExchangeCredentials ewsCredential = new WebCredentials(ewsUserName, ewsPassword, ewsDomain);  
exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);     
exchangeService.setCredentials(ewsCredential);