问题描述
我有一个Exchange 2013服务器(Windows Server 2013)。具有所有角色的单台服务器域控制器,AD,Exchange服务器等。现在,我正在编写基本的Exchange Web服务示例代码。下面是我正在尝试的代码。如果在Exchange服务器本身上运行此代码,则会发送测试电子邮件。但是,如果我在同一域中的另一台Windows 10计算机上运行相同的代码,它将无法正常工作。下面给出了例外。
在Windows10计算机上,我将DNS IP设置为指向Windows Server 2013(Exchange服务器),并可以ping至example.com。我在这里缺少的是,为什么此代码在相同域的Windows 10计算机上不起作用。
也不明白为什么,它正在寻找http://autodiscover.example.com。这不是我在任何地方定义的。
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("User2001@example.com","Pass@123");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("User2001@example.com",RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("User2002@example.com");
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=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=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 User2001@example.com 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>User2001@example.com</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 User2001@example.com 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>User2001@example.com</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 User2001@example.com 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>
解决方法
好像您有安全的连接问题;
过程
- 客户端将LDAP查询发送到AD
- AD返回SCP点列表
- 客户端尝试连接到返回的点
- 如果有一个有效的回复回来,那就开心吧。
在您的情况下,服务器正在返回
https://nileshwin12excg.example.com/Autodiscover/Autodiscover.xml-结果:失败:WebException(基础连接已关闭:无法为SSL / TLS安全通道建立信任关系。)
https://example.com/autodiscover/autodiscover.xml-结果:失败:WebException(基础连接已关闭:无法为SSL / TLS安全通道建立信任关系。)
http://autodiscover.example.com/autodiscover/autodiscover.xml-结果:请求错误:无法解析远程名称:'autodiscover.example.com'
因此,客户端似乎无法建立与https://nileshwin12excg.example.com或https://example.com/的可信连接,请尝试从遇到问题的计算机上访问这些URL。可能是您正在对客户端计算机上不受信任的Web服务使用自签名证书。
编辑
添加
ServicePointManager.ServerCertificateValidationCallback += (sender,cert,chain,sslPolicyErrors) => true;
启动时告诉您应用程序始终接受服务器证书为有效。