none
Outlook 2010 VSTO Add-in attach email to another email have problem RRS feed

  • Question

  • Hi,

        I'm now developing Outlook 2010 VSTO Add-in and have problem.

        When I call Attachments.Add() by adding MailItem, it will return "The attempted operation failed.  An object could not be found."

        I tried and at least the object can print the EntryID (Globals.ThisAddIn.selectedMailItem.EntryID != null)

        However, if I attach an image from computer, the operation is success.

        Here is the partial code I have:

    Outlook.MailItem newEmail = (Outlook.MailItem)Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailType);
    Outlook.Attachments attachments = null; Outlook.Attachment attachment = null; try { attachments = newEmail.Attachments; attachment = attachments.Add(Globals.ThisAddIn.selectedMailItem, Outlook.OlAttachmentType.olEmbeddeditem, 1, "Attached email"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (attachments != null) Marshal.ReleaseComObject(attachments); if (attachment != null) Marshal.ReleaseComObject(attachment); }

        Ref:

            https://social.msdn.microsoft.com/Forums/vstudio/en-US/0e0478dd-2d38-4b25-8073-a1d05cafa25b/forward-email-as-attachment-to-other-accuant?forum=vsto
            https://www.add-in-express.com/creating-addins-blog/2011/08/12/how-to-add-existing-e-mail-message-as-attachment/
            https://social.msdn.microsoft.com/Forums/office/en-US/0049dfc1-aa0d-454e-8f67-2d397a4852bb/attaching-a-mailitem-to-a-mailitem?forum=outlookdev

        I'm not sure how to fix. Thanks



    Sunday, December 30, 2018 6:18 PM

All replies