如何在一次更新中将通过EWS提取的所有电子邮件标记为已读? [英] How can I mark as read all emails fetched through EWS in a single update?

查看:182
本文介绍了如何在一次更新中将通过EWS提取的所有电子邮件标记为已读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了MSDN上的EWS托管API示例,在我的Exchange邮箱帐户中找到所有未读的电子邮件

I followed the EWS Managed API example on MSDN to find all unread email in my Exchange mailbox account.

我后来遍历了每个找到的项目,以便将它们放在列表中我需要在获取每条消息的正文并将其更新为 IsRead = true 的同时返回,如下所示:

I later went through each found item in order to place them in the list I need to return while fetching the body of each message and updating each to IsRead=true as follows:

Folder.Bind(Service, WellKnownFolderName.Inbox);

SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
    new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
//ItemView limits the results to numOfMails2Fetch items
FindItemsResults<Item> foundItems = Service.FindItems(WellKnownFolderName.Inbox, sf,
    new ItemView(numOfMails2Fetch));

if (foundItems.TotalCount > 0)
{
    List<EmailMessage> emailsList = new List<EmailMessage>(foundItems.TotalCount);
    foundItems.Items.ToList().ForEach(item =>
    {
        var iEM = item as EmailMessage;
        emailsList.Add(iEM);
        // update properties
        iEM.IsRead = true;
        iEM.Update(ConflictResolutionMode.AutoResolve);
    });
    // fetches and assign the bodies of each email
    Service.LoadPropertiesForItems(emailsList,PropertySet.FirstClassProperties);
    return emailsList;
} else return null;

是否可以将所有找到的项目更新为 IsRead = true 在单个请求中代替?即

Is it possible to update all of the found items to IsRead=true in a single request instead? I.e. without updating them one by one = better performance and coherent logic.

推荐答案

是的,您可以。 ExchangeService.UpdateItems 是您要在此处使用的方法。请参阅如何:按以下方式批量处理电子邮件在Exchange中使用EWS 了解详情。

Yes, you can. ExchangeService.UpdateItems is the method you want to use here. See How to: Process email messages in batches by using EWS in Exchange for details.

这篇关于如何在一次更新中将通过EWS提取的所有电子邮件标记为已读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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