【问题标题】:Get all emails in mailbox获取邮箱中的所有电子邮件
【发布时间】:2011-11-01 12:30:37
【问题描述】:

如何以最少的 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.

【问题讨论】:

标签: c# exchangewebservices


【解决方案1】:

如果您直接使用 EWS 而不是 EWS 托管 API,则可以使用 FindItemOperation 来执行此操作。 EWS FindItemOperation 将多个 parentFolderIds 作为输入。

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

【讨论】:

  • 这似乎是我需要的。一旦我得到一些工作,我会报告。
【解决方案2】:

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);

【讨论】:

    【解决方案3】:

    作为在邮箱中搜索的替代方法,您可以使用 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);
    

    【讨论】:

      猜你喜欢
      • 2017-06-09
      • 2019-10-24
      • 2011-05-30
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 2014-08-02
      相关资源
      最近更新 更多