我按照MSDN上的EWS托管API示例查找我的Exchange邮箱帐户中所有未读邮件。
然后,我逐个查找每个项目,将它们放入需要返回的列表中,同时获取每个消息的正文并更新每个消息的
然后,我逐个查找每个项目,将它们放入需要返回的列表中,同时获取每个消息的正文并更新每个消息的
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
,而不是逐个更新?即:具有更好的性能和连贯的逻辑。