获取邮箱中的所有电子邮件
如何以最少的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.
。
如果使用EWS,而不是直接的EWS托管API,你可以使用FindItemOperation做到这一点。 EWS FindItemOperation将多个parentFolderIds作为输入。
http://msdn.microsoft.com/en-us/library/aa566107(v=exchg.140).aspx
这似乎是我所需要的。一旦我找到工作,我会报告回来。 – gcso
这似乎是说,ParentFolderId不能在你的过滤器进行访问,因为它尚未加载。
可以指示EWS将其添加到您的文件夹视图来加载它:
FolderView view = new FolderView(int.MaxValue) {Traversal = FolderTraversal.Deep};
view.PropertySet.Add(FolderSchema.ParentFolderId);
var allFolders = exchangeService.FindFolders(folderId,view);
作为替代在邮箱搜索时,你可以使用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);
哪一行触发错误? – sq33G
我使用'FindItems()' – gcso
的最后一行看到我的问题和答案:http://*.com/a/12691639/965722 – Misiu