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

亚历山大大帝

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

ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010);
ews.AutodiscoverUrl("[email protected]");
EmailMessage email = new EmailMessage(ews);
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();

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

ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010);
ews.AutodiscoverUrl("[email protected]");
ews.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");
EmailMessage email = new EmailMessage(ews);
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();

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

ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010);
ews.Credentials = new NetworkCredential("service", "1234", "mydomain.com");
//ews.Credentials = new WebCredentials("service", "1234");
ews.AutodiscoverUrl("[email protected]");
//ews.AutodiscoverUrl("[email protected]");
ews.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");
EmailMessage email = new EmailMessage(ews);
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();

但是,这会在自动发现行中引发错误:“ AutodiscoverLocalException:找不到自动发现服务。”

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

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

亚历山大大帝

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

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

http://mydomain/AutoDiscover/AutoDiscover.xml

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章