Delphi to display embedded image in outlook msg
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 me开发者_开发问答ssage? I am using the imported object library.
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.
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;
精彩评论