我想使用下面的代碼來過濾掉未讀的outlook郵件,但是我想對最近的N個Outlook.Items.App應用這個限制,但是我找不到任何這樣的方法。如何在最近的N個Outlook.Items上應用過濾器並在過濾後獲取Outlook.Items?
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);
}
}
}
}
https://stackoverflow.com/a/43622710/4539709 – 0m3r