Outlook.MailItem.SaveAs method always fails with 0x80004004 (E_ABORT)

0

I am trying to save the current e-mail in Outlook. The code is accessed with a ribbon button. When I do the SaveAs method on the MailItem I always get the 0x80004004 (E_ABORT) exception.

This is my code:

       Outlook._Application outlook = new Outlook.Application();
        if (outlook.ActiveExplorer().Selection.Count > 0)
        {
            Object selectedObject = outlook.ActiveExplorer().Selection[1];

            if (selectedObject is Outlook.MailItem)
            {
                Outlook._MailItem mailItem = (selectedObject as Outlook._MailItem);

                Helpers.CheckDir(userAppPath + @"temp");

                try
                {
                    mailItem.SaveAs(userAppPath + @"temp\tempmail.msg", Outlook.OlSaveAsType.olMSGUnicode);
                    doUpload = true;
                }
                catch (Exception ex)
                {
                    doUpload = false;
                }
            }
        }

If I save it manually from Outlook with the exact same filename and in the same location I can load it back in my code, but I can't save the same e-mail in code using the SaveAs method.

I have tried various OlSaveAsType types. And also the MailItem type instead of the _MailItem type.

Any ideas?

email
outlook
outlook-addin
mailitem
asked on Stack Overflow May 8, 2017 by Lars Næss

2 Answers

1

I have noticed the following aspects:

The code is accessed with a ribbon button.

and

 Outlook._Application outlook = new Outlook.Application();

There is no need to create a new Application instance in the ribbon event handler. Instead, you need to use the Application property of the add-in class.

answered on Stack Overflow May 15, 2017 by Eugene Astafiev
0

Sorry. Found out that the SaveAs Method Works. I just didn't have a correct instance of the current MailItem. Although I don't know why - but that's another question :-)

answered on Stack Overflow May 9, 2017 by Lars Næss

User contributions licensed under CC BY-SA 3.0