我想使用以下代码过滤掉未读的Outlook邮件,但我想在最近的N个Outlook.Items.But上应用此限制我找不到任何此类方法。
Outlook.Explorer currExplorer = null;
Outlook.Folder currFolder = null;
Outlook.Items folderItems = null;
Outlook.Items restrictedItems = null;
Outlook.MailItem mail = null;
Outlook.Attachments attachments = null;
int attachmentCount = 0;
try
{
currExplorer = OutlookApp.ActiveExplorer();
currFolder = currExplorer.CurrentFolder as Outlook.Folder;
if (currFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
{
folderItems = currFolder.Items;
restrictedItems = folderItems.Restrict("[Unread]=true");
for (int i = 1; i <= restrictedItems.Count; i++)
{
mail = restrictedItems[i] as Outlook.MailItem;
if (mail != null)
{
attachments = mail.Attachments;
attachmentCount += attachments.Count;
Marshal.ReleaseComObject(attachments);
Marshal.ReleaseComObject(mail);
}
}
}
}
答案 0 :(得分:0)
您需要使用Restrict
方法两次 - 首先获取最近的N个项目,然后使用第二个来获取它们之间的未读项目。没有查询来获取集合中的N个项目,但您可以使用时间和时间范围来过滤项目,有关详细信息,请参阅Enumerating, Searching, and Filtering Items in a Folder 。
您可能会发现以下文章有用: