编程语言
首页 > 编程语言> > c#-服务帐户中的Exchange模拟:无法找到自动发现服务

c#-服务帐户中的Exchange模拟:无法找到自动发现服务

作者:互联网

通过ews发送简单的电子邮件可以正常工作-从我的帐户到我的帐户:

ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010);
ews.AutodiscoverUrl("myname@mydomain.com");
EmailMessage email = new EmailMessage(ews);
email.ToRecipients.Add("myname@mydomain.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API");
email.Send();

只需尝试模拟,它也可以按预期方式工作-在最后一行中,它返回不允许模拟的错误:

ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010);
ews.AutodiscoverUrl("myname@mydomain.com");
ews.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "testuser@mydomain.com");
EmailMessage email = new EmailMessage(ews);
email.ToRecipients.Add("myname@mydomain.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API");
email.Send();

现在,我尝试使用我的应用程序服务帐户登录:

ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010);
ews.Credentials = new NetworkCredential("service", "1234", "mydomain.com");
//ews.Credentials = new WebCredentials("service", "1234");
ews.AutodiscoverUrl("myname@mydomain.com");
//ews.AutodiscoverUrl("service@mydomain.com");
ews.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "testuser@mydomain.com");
EmailMessage email = new EmailMessage(ews);
email.ToRecipients.Add("myname@mydomain.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API");
email.Send();

但是,这在自动发现行中引发了一个错误:“ AutodiscoverLocalException:找不到自动发现服务.”

该服务帐户已在AD和Exchange中设置,并带有正确的密码和smtp地址.

为什么不起作用?如何检查导致该错误的原因?

解决方法:

我解决了问题,然后猜出了问题所在:这是用户帐户.

EWS使用给定的凭据进行身份验证以访问以下位置的自动发现服务:

http://mydomain/AutoDiscover/AutoDiscover.xml

凭据是正确的,但是对于设置为“用户必须在首次登录时更改密码”的帐户,似乎无法访问自动发现服务.我在AD中更改了该设置,现在可以使用了.

标签:impersonation,exchangewebservices,c
来源: https://codeday.me/bug/20191030/1966182.html