0

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.

paul
  • 135
  • 1
  • 10
  • have you tried using the https://ewseditor.codeplex.com/ to try using the service? Maybe this can help to verify its an API or connectivity/configuration problem. – ccDict Oct 04 '17 at 14:21
  • They are quite strict at work about installing software so I probably would not be able to do it. – paul Oct 04 '17 at 15:38
  • I should also note that I have tried the manual option as well and this has not worked for me ( again, I followed the guidelines provided by the getting started guide). – paul Oct 04 '17 at 15:39
  • from the log I would say you are missing the appropriate DNS records. Sorry but you need to verify if autodiscover works for you at all (ewseditor will do the trick) or if its a general config problem. – ccDict Oct 04 '17 at 16:00
  • Okay I will try and get them to let me download it and I will definitely post a solution to this once I figure this out. Thank you. – paul Oct 04 '17 at 16:31
  • For anyone following, turns out this was an issue with my dependencies. I did not have my gradle integration set up properly: dependencies { compile 'com.microsoft.ews-java-api:ews-java-api:2.0' } – paul Oct 20 '17 at 12:23
  • @paul how dependency can be the issue? – Vishal Patel Nov 15 '19 at 05:41

1 Answers1

1

Order to follow to avoid such errors:

  1. Set Credentials
  2. Set impersonationId
  3. Set autoDiscovery
  4. Set anchorMailbox
David Buck
  • 3,752
  • 35
  • 31
  • 35