我试图以我自己的用户身份运行以下代码。
var email = UserPrincipal.Current.EmailAddress;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.AutodiscoverUrl(email);
FolderId inbox = new FolderId(WellKnownFolderName.Inbox, new Mailbox(email));
service.FindItems(inbox, new ItemView(1000));
此代码在一台机器上有效,但不适用于新机器。相反,我得到了这个异常
Microsoft.Exchange.WebServices.Data.ServiceResponseException was unhandled
HResult=-2146233088
Message=The specified object was not found in the store., The process failed to get the correct properties.
Source=Microsoft.Exchange.WebServices
StackTrace:
at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Responses\ServiceResponse.cs:line 277
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\MultiResponseServiceRequest.cs:line 166
at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable`1 parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view, Grouping groupBy, ServiceErrorHandling errorHandlingMode) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ExchangeService.cs:line 832
at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(FolderId parentFolderId, ViewBase view) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ExchangeService.cs:line 956
除了
,我看不到其他机器之间的任何差异真正令人困惑的是,我在Outlook中的“帐户设置”下配置了两个帐户(第二个是服务帐户邮箱)。如果我将email
变量更改为第二个帐户的电子邮件地址,则一切正常。这使我相信这绝对不是管理员权限的问题,但是我不太清楚问题是什么。