none
MainItem.HTMLBody with img tag won't display image RRS feed

  • Question

  • In .NET I'm using Microsoft.Office.Interop.Outlook.MailItem to create an email and display it to the user. When setting the HTMLBody property, images that don't have 'px' specified don't show when I hit display, but they do if 'px' is specified.

    For example, this will show the image just as you would expect:

    _outlookMailItem.HTMLBody = "<img src=\"file:///C:/example.png\" width=\"200px\" height=\"100px\" />";

    But the following does not show the image, just the reserved space for it.

    _outlookMailItem.HTMLBody = "<img src=\"file:///C:/example.png\" width=\"200\" height=\"100\" />";

    Note the only difference is 'px' is not specified. I don't think it's a html requirement to have 'px' so am wondering if this is a recognised issue? 

    This has become quite a big issue since the html is normally from other software so I'm hoping to find a solution (even if it is short-term) that isn't programmatic.

    Thanks.



    • Edited by stevek5432 Tuesday, September 2, 2014 5:28 AM
    Tuesday, September 2, 2014 5:26 AM

All replies

  • Hello Steve,

    See HTML Email not displaying correctly in Outlook 2007 .

    Anyway, images will not be displayed on the recipient side. You need to embed images and add the "cid:" attribute to attached filename. For example, a raw sketch:

    Attachment attachment = newMail.Attachments.Add( @"E:\Pictures\image001.jpg" , OlAttachmentType.olEmbeddeditem , null , "Some image display name"); string imageCid = "image001.jpg@123";

    Outlook.PropertyAccessor accessor = attachment.PropertyAccessor; accessor.SetProperty( "http://schemas.microsoft.com/mapi/proptag/0x3712001E" , imageCid); newMail.HTMLBody = String.Format( "<body><img src=\"cid:{0}\"></body>" , imageCid);

    Don't forget to release all underlying COM objects instantly.

    Or just use globally available images (uploaded to any web server).


    Tuesday, September 2, 2014 11:08 AM
  • Thanks for the reply Eugune. From the link you provided there seems a lot not to like about working with HTML in email. The thing is, it is working with that slight adjustment and outlook is obviously doing the embedding because the img source does show up for the recipient. Just for some reason Outlook requires img tags needlessly specify 'px' with the width and height - why does something so unnecessary have to trip Outlook up?

    Tuesday, September 2, 2014 11:00 PM
  • > it is working with that slight adjustment and outlook is obviously doing the embedding because the img source does show up for the recipient.

    It seems the recipient keeps pics at the same location. Outlook doesn't embed images if you specify the absolute path in the HTML markup.

    As you may see there are a lot of issues related to the HTML markup in Outlook. I'd suggest you to open a support case if you need to get the simple numbers working instead of specifying the "px" at the end.

    Wednesday, September 3, 2014 8:19 AM
  • Hi Stevek,

    The html code that without px works well in Outlook 2013, which version of Outlook are you using?

    Since I have't enviroment today, I will test it in Outlook 2007 and Outlook 2010 tomorrow.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 9, 2014 11:04 AM
    Moderator
  • Hi Stevek,

    I still failed to fix the environment. I will see whether the environment would be fixed tomorrow.

    Thanks for your understanding.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, September 10, 2014 10:09 AM
    Moderator
  • Hi Stevek,

    The code works well in Outlook 2010 too. The only problem is that the PNG image file can't display in Outlook 2007. And I also found an thread about this topic:
    Outlook 2007 and .png problem

    If you are using Outlook 2007, please check whether it is helpful.

    I also suggest that you update to the Outlook to the latest version to fix this issue.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 11, 2014 9:45 AM
    Moderator