Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) while deleting mails from outlook

1

I want to delete mails from non-default folders of outlook which was archive and copy is present in enterprise vault.It is deleting the first mail and after that I am getting the below error.

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in DeleteOutlookMails.exe

Additional information: Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

Operating system : Windows 10
Outlook Version : 2016

here the code

        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();
                }
            }
        }
    }
c#
outlook
asked on Stack Overflow May 9, 2019 by Vishal Jaiswal • edited May 9, 2019 by Giulio Caccin

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0