Arm*_*oot 3 c# email managed exchangewebservices
我按照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;
Run Code Online (Sandbox Code Playgroud)
是否可以IsRead=true在一个请求中更新所有找到的项目?即不逐一更新它们=更好的性能和连贯的逻辑.
| 归档时间: |
|
| 查看次数: |
5496 次 |
| 最近记录: |