EWS托管API提取所有电子邮件项目错误 [英] EWS Managed API Fetch All Email Item Error

查看:111
本文介绍了EWS托管API提取所有电子邮件项目错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是获取给定文件夹中的所有电子邮件,但我不断收到属性"错误:

My goal is to fetch all emails in a given folder, but I keep getting the Property error:

属性Body不能在FindItem请求中使用

The property Body can't be used in FindItem requests

您能不能请我指出我做错了什么?下面是我使用.NET Framework 4.0的测试代码

Would you some be kind enough to point out what I am doing wrong. Below is my test code using .NET Framework 4.0

private static void GetEmailMessageCollection(ExchangeService service)
  {
     ItemView view = new ItemView(100);

     view.PropertySet = new PropertySet(PropertySet.FirstClassProperties);
     view.PropertySet.Add(ItemSchema.HasAttachments);
     view.PropertySet.Add(ItemSchema.Body);
     view.PropertySet.Add(ItemSchema.DisplayTo);
     view.PropertySet.Add(ItemSchema.IsDraft);
     view.PropertySet.Add(ItemSchema.DateTimeCreated);
     view.PropertySet.Add(ItemSchema.DateTimeReceived);

     FindItemsResults<Item> findResults;
     List<EmailMessage> emails = new List<EmailMessage>();

     string archiveFolderID = " AQEuAAADGF6AegrId0+ekrWv0TJZtgEAZ2jpm1niGUS/jwC23X6j/AAAAgP/AAAA";

     SearchFilter unreadSearchFilter = new SearchFilter.SearchFilterCollection();
     Folder boundFolder = Folder.Bind(service, archiveFolderID );
     findResults = boundFolder.FindItems(unreadSearchFilter, view);


     foreach (var item in findResults.Items)
     {
        emails.Add((EmailMessage)item);
     }

  }

谢谢.

推荐答案

在EWS中使用FindItems操作时,它将仅返回可用于Item的属性的子集.它不会返回的属性之一是Body属性(或任何大于512字节的流属性),请参见

When you use the FindItems operation in EWS it will only return a subset of the properties available for an Item. One of the properties it won't return is the Body property (or any streaming property larger then 512 bytes) see http://msdn.microsoft.com/EN-US/library/office/dn600367(v=exchg.150).aspx

您需要做的是使用GetItem操作来获得此最有效的方法是使用LoadPropertiesForItems方法,该方法将执行批处理GetItem,因此您需要像这样修改代码

What you need to do is use the GetItem operation to get this the most efficient way to do this is use the LoadPropertiesForItems method which will do a batch GetItem so you need to modify you code like

        ItemView view = new ItemView(100);
        view.PropertySet = new PropertySet(PropertySet.IdOnly);
        PropertySet PropSet = new PropertySet();
        PropSet.Add(ItemSchema.HasAttachments);
        PropSet.Add(ItemSchema.Body);
        PropSet.Add(ItemSchema.DisplayTo);
        PropSet.Add(ItemSchema.IsDraft);
        PropSet.Add(ItemSchema.DateTimeCreated);
        PropSet.Add(ItemSchema.DateTimeReceived);

        FindItemsResults<Item> findResults;
        List<EmailMessage> emails = new List<EmailMessage>();
        do
        {
            findResults = service.FindItems(WellKnownFolderName.Inbox, view);
            if (findResults.Items.Count > 0)
            {
                service.LoadPropertiesForItems(findResults.Items, PropSet);
                foreach (var item in findResults.Items)
                {
                    Console.WriteLine(item.Body.Text);
                }
            }
            view.Offset += findResults.Items.Count;
        } while (findResults.MoreAvailable);

欢呼 格伦

这篇关于EWS托管API提取所有电子邮件项目错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆