通过 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 地址。
为什么它不起作用?我如何检查导致该错误的原因?