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); }



        I'm not sure how to fix. Thanks

    Sunday, December 30, 2018 6:18 PM

All replies