0

I am creating an add in for outlook 2007, and what i am trying to do is embed an image to a new email. I cannot get the embedding of the image to work, please help. My code is as follows:

 private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Outlook.Inspectors inspectors;
        inspectors = this.Application.Inspectors;
        inspectors.NewInspector +=
        new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }

    void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
    {
        Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
        if (mailItem != null)
        {
            if (mailItem.EntryID == null)
            {
                mailItem.Subject = "This text was added by using code";
                mailItem.HTMLBody = "<html><body>this is a <img src=" + @"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg> embedded picture.</body></html>";
                //mailItem.HtmlBody = "<html><body>this is a <img src=\"cid:" + @"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg" + "\"> embedded picture.</body></html>";
            }

        }
    }

but this is not displaying the image. Please help.

Thanks in advance.

johnnie
  • 1,837
  • 5
  • 23
  • 36
  • Did this work for you? [VSTO Outlook Embed Image MailItem][1] [1]: http://stackoverflow.com/questions/4196160/vsto-outlook-embed-image-mailitem – MyKuLLSKI Jan 31 '12 at 16:51

1 Answers1

0

While I haven't used the Outlook components directly, you're going to need to embed the image in the mail. All you are doing in the code above is creating a string that references an image on your local hard drive.

In my world, I iuse the .NET mail components, so take this with a grain of salt, but the concepts should transfer. I do something like this:

AlternateView htmlView = AlternateView.CreateAlternateViewFromString(model.MessageBody_Html, null, MediaTypeNames.Text.Html);

ImgStream   = new MemoryStream(media.MediaData); 
linkedImage = new LinkedResource(ImgStream, MediaTypeNames.Image.Jpeg);
linkedImage.ContentId    = "img_" + media.MediaID;
linkedImage.TransferEncoding    = TransferEncoding.Base64;
htmlView.LinkedResources.Add(linkedImage);

Also, when creating HTML Messages it is considered good practice to include a plain text version.

EBarr
  • 11,826
  • 7
  • 63
  • 85