我想从Outlook的非默认文件夹中删除已存档和复制的邮件,而该文件夹在企业保管库中存在。它正在删除第一封邮件,然后出现以下错误。
DeleteOutlookMails.exe中发生了'System.Runtime.InteropServices.COMException'类型的未处理异常
其他信息:操作中止(HRESULT的异常: 0x80004004(E_ABORT))
操作系统:Windows 10
Outlook版本:2016
此处是代码
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace ns = app.GetNamespace("MAPI");
foreach (MAPIFolder f in ns.Folders)
{
getFolder(f);
}
}
public void getFolder(MAPIFolder fl)
{
if (fl.Folders.Count > 0)
{
foreach (MAPIFolder subFolder in fl.Folders)
{
if (subFolder.Name.Equals("Inbox"))
{
DeleteMails(subFolder);
}
}
}
}
public void DeleteMails(MAPIFolder mf)
{
if (mf.Folders.Count > 0)
{
foreach (MAPIFolder m in mf.Folders)
{
Console.WriteLine(m.Name);
while (m.Items.Count > 0)
{
MailItem DeleteMail = (MailItem)m.Items.GetFirst();
DeleteMail.Delete();
}
}
}
}