Exchange服务Finditems给出407错误

时间:2016-06-15 11:07:25

标签: c#-4.0 exchange-server exchangewebservices

我们需要从outlook.com搜索电子邮件并实现此目的,我们正在使用Exchange Web服务(EWS),但在调用FindItem服务方法时遇到407错误。

以下是我们正在处理的代码 -

List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
        searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Test"));
        //searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Body, "homecoming"));
        SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());

        ItemView view = new ItemView(50);
        // Identify the properties to return in the result set and the additional properties that are returned for each item.
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived);
        //Order the search results by the DateTimeReceived property. The sort direction is in descending order.

        view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);

        //Set the manner by which the search filter traverses the target folder. In the following example, the search filter performs a shallow traversal. Shallow is the default option; other traversal options are Associated and SoftDeleted.

        view.Traversal = ItemTraversal.Shallow;

        string userEmailAddress = "username@outlook.com";
        string userPassword = "OutlookPassword";
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);


        service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
        service.Credentials = new WebCredentials(userEmailAddress, userPassword);
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);

在最后一行代码中获取错误。

您能指导一下需要解决的问题吗? 谢谢!

0 个答案:

没有答案