Reputation: 392
I have a Exchange 2013 server (Windows Server 2013). Single server with all roles Domain controller, AD, Exchange server etc. Now I am writing basic Exchange web services sample code. Below is the code I am trying. If run this code on Exchange server itself, test email gets sent. But if I run same code on another Windows 10 machine in same domain, it does not works. It gives exception below.
On Windows10 machine I have set DNS IP to point Windows Server 2013(Exchange server), with that I can ping to example.com. What I am missing here, why this code is not working on Windows 10 machine in same domain.
Also did not understand why, it is looking for http://autodiscover.example.com. This is not I have defined anywhere.
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("[email protected]", "Pass@123");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("[email protected]");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API");
email.Send();
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
return true;
}
Unhandled Exception: Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located.
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List`1 redirectionEmailAddresses, Int32& currentHop)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List`1 requestedSettings)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
at EWSTest.Program.Main(String[] args) in c:\users\administrator\source\repos\EWSTest\EWSTest\Program.cs:line 18
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:16Z">
Starting SCP lookup for domainName='example.com', root path=''
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:20Z">
Searching for SCP entries in LDAP://CN=Configuration,DC=example,DC=com
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:21Z">
Scanning for SCP pointers Domain=example.com
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:23Z">
No SCP pointers found for 'Domain=example.com' in configPath='CN=Configuration,DC=example,DC=com'
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:24Z">
Scanning for SCP urls for the current computer Site=Default-First-Site-Name
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:24Z">
Adding (prio 1) 'https://NileshWin12Excg.example.com/Autodiscover/Autodiscover.xml' for the 'Site=Default-First-Site-Name' from 'LDAP://CN=NILESHWIN12EXCG,CN=Autodiscover,CN=Protocols,CN=NILESHWIN12EXCG,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=exampleOrg,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=example,DC=com' to the top of the list (exact match)
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:24Z">
Trying to call Autodiscover for [email protected] on https://nileshwin12excg.example.com/Autodiscover/Autodiscover.xml.
</Trace>
<Trace Tag="AutodiscoverRequestHttpHeaders" Tid="1" Time="2020-11-08 05:52:25Z">
POST /Autodiscover/Autodiscover.xml HTTP/1.1
Content-Type: text/xml; charset=utf-8
Accept: text/xml
User-Agent: ExchangeServicesClient/15.00.0913.015
</Trace>
<Trace Tag="AutodiscoverRequest" Tid="1" Time="2020-11-08 05:52:25Z" Version="15.00.0913.015">
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
<Request>
<EMailAddress>[email protected]</EMailAddress>
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
</Request>
</Autodiscover>
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.)
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
Trying to call Autodiscover for [email protected] on https://example.com/autodiscover/autodiscover.xml.
</Trace>
<Trace Tag="AutodiscoverRequestHttpHeaders" Tid="1" Time="2020-11-08 05:52:27Z">
POST /autodiscover/autodiscover.xml HTTP/1.1
Content-Type: text/xml; charset=utf-8
Accept: text/xml
User-Agent: ExchangeServicesClient/15.00.0913.015
</Trace>
<Trace Tag="AutodiscoverRequest" Tid="1" Time="2020-11-08 05:52:27Z" Version="15.00.0913.015">
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
<Request>
<EMailAddress>[email protected]</EMailAddress>
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
</Request>
</Autodiscover>
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.)
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
Trying to call Autodiscover for [email protected] on https://autodiscover.example.com/autodiscover/autodiscover.xml.
</Trace>
<Trace Tag="AutodiscoverRequestHttpHeaders" Tid="1" Time="2020-11-08 05:52:27Z">
POST /autodiscover/autodiscover.xml HTTP/1.1
Content-Type: text/xml; charset=utf-8
Accept: text/xml
User-Agent: ExchangeServicesClient/15.00.0913.015
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
failed: WebException (The remote name could not be resolved: 'autodiscover.example.com')
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
Trying to get Autodiscover redirection URL from http://autodiscover.example.com/autodiscover/autodiscover.xml.
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
Request error: The remote name could not be resolved: 'autodiscover.example.com'
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
No Autodiscover redirection URL was returned.
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
Trying to get Autodiscover host from DNS SRV record for example.com.
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:28Z">
DnsQuery returned error error 'DNS name does not exist' error code 0x0000232B.
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:28Z">
No appropriate SRV record was found.
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:28Z">
No matching Autodiscover DNS SRV records were found.
</Trace>
Upvotes: 0
Views: 2138
Reputation: 1430
Looks like you having secure connection issues;
Process
In your case the server is returning
https://nileshwin12excg.example.com/Autodiscover/Autodiscover.xml - Result : failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.)
https://example.com/autodiscover/autodiscover.xml - Result : failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.)
http://autodiscover.example.com/autodiscover/autodiscover.xml - Result : Request error: The remote name could not be resolved: 'autodiscover.example.com'
So it would seem that the client can not establish a trusted connection to https://nileshwin12excg.example.com or https://example.com/, try to get to these URLs from the machine where you are having trouble. It may be you are using self-signed certs for your web services that are not trusted on the client machine.
EDIT
Add
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
To your startup to tell you application to always accept the server certificate as valid.
Upvotes: 1