2

I am reading outlook msg files in Delphi 2010 and displaying the html body of a message in a twebbrowser. It does not however display the embedded image. Hot to display embedded images in outlook message? I am using the imported object library.

2 Answers2

4

Embedded images in HTML mail come with src="cid:xx" attribute where xx is the content ID of the image part (Content-Type: application/octet-stream; Content-Disposition: inline) in the multi-part MIME message. You could decode and save that part to a temporary file and fix up the src attribute of the img element to point to the temporary image file. An alternative to "serve" images to the browser through an asynchronous pluggable protocol is described here.

Community
  • 1
  • 1
Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • 1
    @Rawn: implementing the cid protocol may not be simple if you're not used to work with COM interfaces, but it's the best way to ensure everything works fine instead of trying to modify the mail HTML, because the protocol is very generic and not limited to images. To find publicy available code you may try to look for "IInternetProtocolRoot, IInternetProtocol, IInternetProtocolInfo" interfaces. –  Jun 08 '11 at 09:42
  • I've created an IInternetProtocol implementation once, [here][1] And you'll probably also need [RegisterNameSpace][2] [1]: http://xxm.svn.sourceforge.net/viewvc/xxm/trunk/Delphi/local/ [2]: http://msdn.microsoft.com/en-us/library/aa767759%28v=vs.85%29.aspx – Stijn Sanders Jun 11 '11 at 13:56
  • @StijnSanders Is the Gecko sdk up to date? –  Sep 27 '13 at 11:41
  • what do you mean? I've given up on the xxm Gecko handler since the rapid release schedule. To make it work again, I need to figure out how to do a nsIProtocolHandler from javascript and pass *everything* into an xxm DLL with js-ctypes. I tried both but haven't been successful up till now. – Stijn Sanders Sep 27 '13 at 23:13
0

You could use the IHTMLDocument2 interface to do the work for you: (see: http://k210.org/delphi/internet/23/ - create IHTMLDocument2 runtime)

(note: msg = the mail message)

var
   slImages : TStringList;
   ADoc     : IHTMLDocument2;
begin
   slImages := TStringList.create;
   try
      ADoc  := CreateAndLoadIHTMLdoc2AtRuntime(sBody);
      sBody := ConvertHTMLToHTMLWithEmbeddedImages(Adoc, slImages);

      if (slImages.count=0) then
         msg.HTMLBody:= sBody
      else // add attachments + set cid's in this routine   
         SetupEmbeddedImages(msg, sBody, slImages);

   finally
      freeandNil(slImages);
   end;
end;
tomo7
  • 451
  • 7
  • 6