Incrustar una imagen en el cuerpo del correo electrónico

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.

Gracias de antemano.

preguntado el 31 de enero de 12 a las 16:01

Did this work for you? [VSTO Outlook Embed Image MailItem][1] [1]: stackoverflow.com/questions/4196160/… -

1 Respuestas

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.

Respondido el 31 de enero de 12 a las 20:01

Hi there could you please post some code to accomplish this. Thanks. - Johnnie

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.