在几个公共文件夹中,大约有15个特定的公用文件夹,我将从中删除超过15天的邮件项目。每个公用文件夹都有大约1000多个mailitems。每周都有相同数量的商品。目前,我正在获取默认公用文件夹并循环每个子文件夹并删除邮件。
Microsoft.Office.Interop.Outlook.Folder tempInbox = tempApp.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders) as Microsoft.Office.Interop.Outlook.Folder;
**SOME Code***
foreach (Microsoft.Office.Interop.Outlook.Folder subfolder1 in subfolder.Folders)
{
if ((check those 14 subfolder names )& (subfolder1.Folders.Count > 0))
{
CheckCountries(subfolder1, sw);
}
}
CheckCountries(subfolder1, sw) -> Here I am comparing and deleting the mail items.
//Deletion part of code below
foreach (object todel in delItem)
{
DateTime d1 = DateTime.Now;
Microsoft.Office.Interop.Outlook.MailItem mailitmType = todel as Microsoft.Office.Interop.Outlook.MailItem;
if (mailitmType is Microsoft.Office.Interop.Outlook.MailItem)
{
if ((mailitmType.IsConflict != true) & (mailitmType.MessageClass.Contains("IPM.Note.SMIME") == false))
{
DateTime d2 = mailitmType.ReceivedTime;
if ((d1 - d2).TotalDays > iDays)
{
sw.WriteLine("Deleting Mail with Subject line as = \"" + mailitmType.Subject + "\" and Received time = " + mailitmType.ReceivedTime);
mailitmType.Delete();
iCnt = iCnt + 1;
} //mailitmType.Save();
}
}
}
我希望改进以下几个方面 -
答案 0 :(得分:0)
永远不要遍历文件夹中的所有项目 - 使用Items.Find/FindNext
Items.Restrict
ReceivedTime
appium &
属性的查询小于某个值。