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
867 stars 558 forks source link

AutodiscoverLocalException but Outlook autodiscover is working #557

Open sVeloper opened 7 years ago

sVeloper commented 7 years ago

Hello, i´am trying to connect local on my exchange server 2010. When i try it within outlook "E-Mail AutoConfiguration test", its works finde. Here is my xml file from Outlook:

OUTLOOK-OUPUT.txt

but when i try to discover within my code, i get exception. My trace is like that:

trace.txt

Here is my code:

service = new ExchangeService(ExchangeVersion.Exchange2010);
        ExchangeCredentials credentials = new WebCredentials("FirstName.SecondName", myPW, "exchange2010.intern.mycompany.com");
        service.setCredentials(credentials);
        service.setTraceEnabled(true);
service.setTraceFlags(EnumSet.allOf(TraceFlags.class)); 
        service.setTraceListener(new ITraceListener() {

            public void trace(String traceType, String traceMessage) {

                System.out.println("Type:" + traceType + " Message:" + traceMessage);
            }
        }); 
service.autodiscoverUrl("Firstname.SecondName@mycompany.com", 
                   new IAutodiscoverRedirectionUrl() {
                        public boolean autodiscoverRedirectionUrlValidationCallback(String url) throws   
                                             AutodiscoverLocalException {

                            return url.toLowerCase().startsWith("https://");
                        }
                    });

I ` am using Microsoft Outlook 2010 What could i try ? Thx.

sVeloper commented 7 years ago

Within my Outlook-Autodiscover-test.xml i can read this:

    <User>
      <DisplayName>Firstname Secondname</DisplayName>
      <LegacyDN>/o=etecture/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Roman Kaptsana79</LegacyDN>
      <AutoDiscoverSMTPAddress>Firstname.Secondname@mycompany.com</AutoDiscoverSMTPAddress>
      <DeploymentId>b928fce2-bc7b-4dea-9f1f-51785f9f2f5e</DeploymentId>
    </User>

It means, that host "mycompany.com" works fine. And when i use AutoDiscoverSMTPAddress (Firstname.Secondname@mycompany.com ) by code: service.autodiscoverUrl("Firstname.Secondname@mycompany.com")

My tracelog says: No Autodiscover endpoints are available for host mycompany.com How could it be?

sVeloper commented 7 years ago

I have imported existing crt- certificate like this:

Download crt-certificate from outlook-browser gui.

2 import with keytool: C:\Program Files\Java\jdk1.8.0\bin>keystore.jks importcdert -alicas startssl -keystore ..\jre\lib\security\cacerts -storepass changeit -file C:\Users\mail_certificate.mycompany.com.crt

. Set Property within java-code:

    systemProps.put(
            "javax.net.ssl.trustStore",
            "C:/Program Files/Java/jdk1.8.0/jre/lib/security/cacerts"
        );
    systemProps.put("javax.net.ssl.trustStorePassword","changeit");
    System.setProperties(systemProps);

And i still can not autodiscovering and when i set url explicitly, i get:

.ServiceRequestException: The request failed. The request failed. The remote server returned an error: (401)Unauthorized

I can see fingerprint within keystore, which i´ve imported.

What can i do?