-->

交易所EWS按日期托管API 2.0 GET(Exchange EWS Managed API 2.

2019-10-17 20:45发布

使用EWS托管API林到我的C#项目和我们的Exchange 2010服务器之间的通信。 我用这个代码来获得在收件箱中的所有邮件从现在起,三天回来。

    var ews = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
    ews.Credentials = new NetworkCredential(usr, psw, dmn);
    ews.AutodiscoverUrl(url);

    PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
    itempropertyset.RequestedBodyType = BodyType.Text;

    ItemView view = new ItemView(int.MaxValue);
    FindItemsResults<Item> findResults;
    view.PropertySet = itempropertyset;

    do
    {
        findResults = ews.FindItems(WellKnownFolderName.Inbox, view);

        foreach (Item item in findResults.Items)
        {
            if (item.DateTimeCreated < DateTime.Now.AddDays(-3)) continue;

            item.Load(itempropertyset);

            var message = EmailMessage.Bind(ews, item.Id,
                new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments));

            string to = message.ToRecipients[0].Address.ToLower();
            string body = item.Body;
        }

        view.Offset += findResults.TotalCount;
    } while (findResults.MoreAvailable);

现在的问题。 我想提高此线if (item.DateTimeCreated < DateTime.Now.AddDays(-3)) continue; 因为当我用这个,这个API得到所有从收件箱中的消息,只是继续如果旧的然后三天。 我想在前面的代码指定此过滤器,因此API不必须处理所有消息。

Answer 1:

如果我理解正确的问题,这应该工作。 你可以看到这里提供所有搜索过滤器: EWS搜索过滤器

ItemView view = new ItemView(int.MaxValue);
FindItemsResults<Item> findResults;
view.PropertySet = itempropertyset;

SearchFilter searchFilter = 
   new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived, DateTime.Now.AddDays(-3));

findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);


文章来源: Exchange EWS Managed API 2.0 get by date