c# - 尝试使用 EWS MANAGED API 访问 Exchange 2010 帐户时“找不到自动发现服务”

标签 c# exchange-server exchangewebservices ews-managed-api

我正在为指定的电子邮件地址使用自动发现服务 Url。

ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2010);
Service.Credentials = new WebCredentials("username@domainname.com", "Password");
Service.AutodiscoverUrl("username@domainname.com");
Folder inbox = Folder.Bind(Service, WellKnownFolderName.Inbox);
Console.WriteLine("The folder name is" + inbox.DisplayName.ToString());

如果我这样做,我会出错:

The Autodiscover service couldn't be located

我必须怎么做才能避免这个错误?

最佳答案

你的 Service.Credentials 错了,像这样使用它:

Service.Credentials = new WebCredentials(username, password, domainname);

使用域凭据,而不是电子邮件地址。

还要仔细检查以下内容:

  1. 您在 new ExchangeService() 中指定的版本与服务器的相匹配
  2. 传递给Service.AutodiscoverUrl();的参数正确(需要抓取数据的邮箱地址)

以下对我有用(在新的控制台应用程序中):

// Tweaked to match server version
ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); 

// Dummy but realistic credentials provided below
Service.Credentials = new WebCredentials("john", "12345678", "MYDOMAIN");
Service.AutodiscoverUrl("john.smith@mydomain.it");
Folder inbox = Folder.Bind(Service, WellKnownFolderName.Inbox);
Console.WriteLine("The folder name is " + inbox.DisplayName.ToString());

//Console output follows (IT localized environment, 'Posta in arrivo' = 'Inbox')
> The folder name is Posta in arrivo

关于c# - 尝试使用 EWS MANAGED API 访问 Exchange 2010 帐户时“找不到自动发现服务”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15065363/

相关文章:

c# - 如何将 Nullable<T> 参数与 nHibernate Linq 表达式一起使用?

c# - 为什么 null+false 与 null +"false"不同?

java - 从用户名outlook java获取电子邮件地址

java - android 中的基本身份验证错误 "HTTP/1.1 401 Unauthorized"- EWS 2010

PHP:Microsoft Exchange 问题,PHP 中没有电子邮件正文

exchangewebservices - Exchange Web Services SyncFolderItems 重复项目在实际重复时将 IsRecurring 设置为 false

c# - 基类不包含无参数构造函数?

c# - 如何在 xaml 中裁剪图像并限制图像宽度? (温特)

c# - 获取Outlook中所有房间的列表

c# - 如何使用 ExchangeService 访问共享邮箱 (Outlook 2013)