我正在为指定的电子邮件地址使用自动发现服务 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);
使用域凭据,而不是电子邮件地址。
还要仔细检查以下内容:
- 您在
new ExchangeService()
中指定的版本与服务器的相匹配 - 传递给
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/