How can I mark as read all emails fetched through EWS in a single update?

风格不统一 提交于 2019-12-23 21:24:26

问题


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

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;

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.


回答1:


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.



来源:https://stackoverflow.com/questions/35203239/how-can-i-mark-as-read-all-emails-fetched-through-ews-in-a-single-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!