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

  • Question

  • 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.

    The path is local and can be similar to this: C:\Users\ln\AppData\Roaming\ALMIntegrator\temp\tempmail.msg

    Any ideas?

    Tuesday, May 9, 2017 1:18 PM

All replies

  • Hello Lars,

    > The code is accessed with a ribbon button.

    Then why do you create a new Application instance in the code?

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

    You need to check whether a file with the same name exists on the disk already. I'd suggest adding any marker to the filename to make it unique (current date and time, for example).


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, May 9, 2017 3:43 PM
  • Thanks. Good question :-) How do you get access to the already running instance of Outlook? I assume that's what you point out.

    The filename is not relevant. It fails in the same way whether the folder is empty or not.


    • Edited by LarsNæss Tuesday, May 9, 2017 6:49 PM
    Tuesday, May 9, 2017 6:48 PM
  • 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 :-)
    Tuesday, May 9, 2017 9:14 PM
  • Hi LarsNæss,

    you had mentioned that,"Sorry. Found out that the SaveAs Method Works. I just didn't have a correct instance of the current MailItem."

    it seems that your issue is solved now.

    if yes then try to mark your last post as an answer.

    so that we can close this thread.

    if you do not mark the answer then this thread will remain open.

    so mark the answer and help us to close this thread.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 10, 2017 5:47 AM
    Moderator
  • 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 :-)
    Hopefully you or someone will see this, but I'd like to know how you manage to work with the right instance.
    Monday, June 4, 2018 2:49 PM