把所有的邮件都放在邮箱里

本文关键字: | 更新日期: 2023-09-27 18:13:03

如何在最少的EWS呼叫中获取Exchange 2010中的所有邮件?

我们的邮箱有50k多封邮件和2k个文件夹。我试着遍历每个文件夹,但这需要几个小时才能取出我所有的电子邮件。我目前的方法是从邮箱中获取所有文件夹,然后制作一个搜索过滤器列表,基本上过滤父文件夹id为n的所有项目。

这是我到目前为止写的。

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 Managed API,您可以使用FindItemOperation来完成此操作。EWS FindItemOperation接受多个parentfolderid作为输入。

http://msdn.microsoft.com/en-us/library/aa566107 (v = exchg.140) . aspx

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

这似乎说ParentFolderId不能在你的过滤器中访问,因为它还没有加载。

您可以通过将它添加到您的FolderView中来指示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" - 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);
相关文章:
  • 没有找到相关文章