我按照 MSDN 上的 EWS 托管 API 示例进行操作查找我的 Exchange 邮箱帐户中所有未读的电子邮件 https://msdn.microsoft.com/en-us/library/office/dn535506%28v=exchg.150%29.aspx#bk_getewsma.
后来我检查了每个找到的项目,以便将它们放入我需要返回的列表中,同时获取每条消息的正文并将每条消息更新为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。无需一一更新=更好的性能和连贯的逻辑。
是的你可以。ExchangeService.UpdateItems
是您要在此处使用的方法。看如何:使用 Exchange 中的 EWS 批量处理电子邮件 https://msdn.microsoft.com/EN-US/library/office/dn595098(v=exchg.150).aspx了解详情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)