【问题标题】:Exchange Impersonation in Service Account: Autodiscover service couldn't be located服务帐户中的 Exchange 模拟:找不到自动发现服务
【发布时间】:2013-11-23 10:29:22
【问题描述】:

通过 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 地址正确。

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

【问题讨论】:

    标签: c# impersonation exchangewebservices


    【解决方案1】:

    我解决了问题,猜猜问题出在哪里:是用户帐户。

    EWS 使用给定的凭据对自己进行身份验证,以便访问自动发现服务

    http://mydomain/AutoDiscover/AutoDiscover.xml
    

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

    【讨论】:

      【解决方案2】:

      如果这是本地域,请尝试使用mydomain 而不是mydomain.com

      我发现 .com.local 不适合我。

      如果是 Office365 服务器,请使用nullstring.Empty 作为域。

      【讨论】:

        【解决方案3】:

        我在主机文件中添加了以下几行,它对我有用;

        192.168.32.43       mail.mydomain.com            
        192.168.32.43       autodiscover.mydomain.com
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-10-16
          • 2013-02-10
          • 2012-09-28
          • 2016-12-17
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多