I am trying to connect with this code and others similar that I have taken from the getting started guide and no matter what I do I keep getting the error:
The Autodiscover service couldn't be located.
I cannot seem to find or resolve this.
import java.net.URI;
import microsoft.exchange.webservices.data.ExchangeCredentials;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.ExchangeVersion;
import microsoft.exchange.webservices.data.Folder;
import microsoft.exchange.webservices.data.IAutodiscoverRedirectionUrl;
import microsoft.exchange.webservices.data.WebCredentials;
import microsoft.exchange.webservices.data.WellKnownFolderName;
public class Main {
public static class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl {
public boolean autodiscoverRedirectionUrlValidationCallback(String redirectionUrl) {
return redirectionUrl.toLowerCase().startsWith("https://");
}
}
public static ExchangeService connectViaExchangeAutodiscover(String email, String password) {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
try {
service.setCredentials(new WebCredentials(email, password));
service.autodiscoverUrl(email, new RedirectionUrlCallback());
service.setTraceEnabled(true);
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);
System.out.println("messages: " + inbox.getTotalCount());
}
catch (Exception e){
e.printStackTrace();
}
return service;
}
public static void main(String[] args) {
try {
System.out.println("Hello World");
ExchangeService service = connectViaExchangeAutodiscover("user@domain.com", "xxxxxx");
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is a trace report if someone can help me troubleshoot it.
Type:AutodiscoverConfiguration Message: Determining which endpoints are enabled for host wont let me post the link
Type:AutodiscoverConfiguration Message: No Autodiscover endpoints are available for host wont let me post the link
Type:AutodiscoverConfiguration Message: Determining which endpoints are enabled for host wont let me post the link
Type:AutodiscoverConfiguration Message: No Autodiscover endpoints are available for host wont let me post the link
Type:AutodiscoverConfiguration Message: Trying to get Autodiscover redirection URL from wont let me post the link.
Type:AutodiscoverConfiguration Message: No Autodiscover redirection URL was returned.
Type:AutodiscoverConfiguration Message: Trying to get Autodiscover host from DNS SRV record for xxxxx.com.
Type:AutodiscoverConfiguration Message: DnsQuery returned error error 'null' error code 0x{1:X8}.
Type:AutodiscoverConfiguration Message: No appropriate SRV record was found.
Type:AutodiscoverConfiguration Message: No matching Autodiscover DNS SRV records were found.
Type:AutodiscoverResponse Message: Autodiscover service call failed with error 'The Autodiscover service couldn't be located.'. Will try legacy service
Type:AutodiscoverConfiguration Message: Trying to call Autodiscover for xxxxxx@xxxxx.com on wont let me post the link.
Type:AutodiscoverConfiguration Message: null failed: wont let me post the link (wont let me post the link : Connection error )
Type:AutodiscoverConfiguration Message: Trying to call Autodiscover for xxxxxx@xxxxx.com on wont let me post the link.
Type:AutodiscoverConfiguration Message: null failed: wont let me post the link (wont let me post the link : Connection error )
Type:AutodiscoverConfiguration Message: Trying to get Autodiscover redirection URL from wont let me post the link.
Type:AutodiscoverConfiguration Message: No Autodiscover redirection URL was returned.
Type:AutodiscoverConfiguration Message: Trying to get Autodiscover host from DNS SRV record for xxxxx.com.
Type:AutodiscoverConfiguration Message: DnsQuery returned error error 'null' error code 0x{1:X8}.
Type:AutodiscoverConfiguration Message: No appropriate SRV record was found.
Type:AutodiscoverConfiguration Message: No matching Autodiscover DNS SRV records were found.