【问题标题】:How can I mark as read all emails fetched through EWS in a single update?如何在一次更新中将通过 EWS 获取的所有电子邮件标记为已读?
【发布时间】:2016-05-14 04:42:07
【问题描述】:

我按照 MSDN 上的 EWS 托管 API 示例访问了 find all unread email in my Exchange mailbox account。

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

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? IE。无需一一更新 = 更好的性能和连贯的逻辑。

【问题讨论】:

    标签: c# email exchangewebservices managed


    【解决方案1】:

    是的,你可以。 ExchangeService.UpdateItems 是您要在此处使用的方法。详情请见How to: Process email messages in batches by using EWS in Exchange。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 2012-09-23
    • 2014-10-09
    • 2015-07-30
    相关资源
    最近更新 更多