2011-11-01 68 views
1

如何以最少的EWS電話數量從Exchange 2010獲取所有電子郵件?獲取郵箱中的所有電子郵件

我們的郵箱有2k個文件夾的50k +電子郵件。我已經嘗試遍歷每個文件夾,但這需要幾個小時來獲取我的所有電子郵件。我目前的做法是從郵箱中提取所有文件夾,然後製作一個搜索過濾器列表,基本上篩選父文件夾ID爲的所有項目,其中包括

這是我到目前爲止。

var allFolders = exchangeService.FindFolders(folderId, 
              new FolderView(int.MaxValue) {Traversal = FolderTraversal.Deep}); 
var searchFilterCollection = new List<SearchFilter>(); 

foreach(var folder in allFolders) 
    searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.Or, 
     new SearchFilter.IsEqualTo(ItemSchema.ParentFolderId, folder.Id.ToString()))); 

var itemView = new ItemView(int.MaxValue) 
        { 
         PropertySet = PropertySet.FirstClassProperties 
        }; 
var findItems = exchangeService.FindItems(folderId, 
    new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection), itemView); 

我收到的錯誤The property can not be used with this type of restriction.

+0

哪一行觸發錯誤? – sq33G

+0

我使用'FindItems()' – gcso

+0

的最後一行看到我的問題和答案:http://stackoverflow.com/a/12691639/965722 – Misiu

回答

1

http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/4bd4456d-c859-4ad7-b6cd-42831f4fe7ec/

這似乎是說,ParentFolderId不能在你的過濾器進行訪問,因爲它尚未加載。

可以指示EWS將其添加到您的文件夾視圖來加載它:

FolderView view = new FolderView(int.MaxValue) {Traversal = FolderTraversal.Deep}; 
view.PropertySet.Add(FolderSchema.ParentFolderId); 
var allFolders = exchangeService.FindFolders(folderId,view); 
0

作爲替代在郵箱搜索時,你可以使用AllItems文件夾,並做使用MAPI屬性 「PR_PARENT_ENTRYID」 一searchfilter - https://technet.microsoft.com/de-de/sysinternals/gg158149

// use MAPI property from Items parent entry id 
ExtendedPropertyDefinition MAPI_PARENT_ENTRYID = new ExtendedPropertyDefinition(0x0E09, MapiPropertyType.Binary); 

// get the "AllItems" folder from its account 
folderResult = service.FindFolders(WellKnownFolderName.Root, new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "allitems"), folderView); 
var allItemsFolder = folderResult.FirstOrDefault(); 

// convert EWS Folder Id to MAPI ENTRYID - parentFolderId is us an AlternateId 
var convertedId = service.ConvertIds(parentFolderId, IdFormat.EntryId); 

// use the MAPI Property with its converted PARENT_ENTRY_ID in EWS Searchfilters 
var parent_entry_id = (ids.ConvertedId as AlternateId).UniqueId; 
var searchFilterFolders = new SearchFilter.IsEqualTo(MAPI_PARENT_ENTRYID, parent_entry_id); 

// search in "AllItems" using the searchFilter containing the converted PARENT_ENTRY_ID 
result = service.FindItems(folderId, searchFilterFolders, view); 
相關問題