TRichEdit to Outlook email

We are using a TRichEdit (tried TcxRichEdit and TadvRichEdit) to create an Outlook email. This all works fine until we introduce images. These are just left out when we assign the message body. All other RTF aspects are fine in the resulting message, just the images are left out, not even a place holder. This is with the BodyType as HTML or RTF.
If we copy and paste from the RTF to the email body in Outlook, the images are fine. But we can’t do that in the production system.
This appears to be a newish Outlook thing, it used to work fine.
Trying to assign to RTFBody crashes Outlook. And using the TMS conversion to HTML also leaves the images behind.
Any ideas how to get this working? Much searching online, but no solution yet.

1 Like

Hi David,
Is it possible to get a copy of your solution?

I’m slowly adding an email feature to our inhouse app and next on my feature list was images. It sounds like I was about to head back into the swamp.

Shane van de Vorstenbosch

The trick appears to be to use HTML, the TMS TRichEditor component has a function ContentAsHTML. This uses cid: to include the image. With the cid: tag, the image also needs to be added as an attachment.

This was apparently not working correctly in the TMS code, but a few tweaks apparently sorted it out. I am not the one working on this, perhaps John Diamond could elaborate?


No problem Dave. I hope this helps someone else avoid some hassles.

The control used was TAdvRichEditor and yes you need to use HTML to get inline images working in Outlook and it seems it must use Content-ID as the image embedding method (this post was very helpful Every other method is blocked / doesn’t work for Outlook as mentioned in the link.

By default the HTML produced by the TMS html designer is not enough to get it working.
TMS advise you to set TAdvRichEditor.HTMLImages := igID; Which will create a CID html tag when you insert an image but you need more than that to make Outlook happy.

You need to add the image as an attachment, and set the content-ID for it (helpfully named DisplayName in the Outlook Object Model).

Here’s some code (not in finished form yet just shows me it works):

procedure TfrmEmailEditor.Button1Click(Sender: TObject);
OL, OMI: Variant;
Attachment: Variant;
OL := CreateOLEObject(‘Outlook.Application’);
OMI := OL.CreateItem(0);
OMI.BodyFormat := 2; // = olFormatHTML
OMI.To := ‘’;
OMI.Subject := ‘Test email for outlook with inline image’;
OMI.HTMLBody := moHTML.Lines.text;
Attachment := OMI.Attachments.Add(‘C:\Temp\image1.PNG’);
Attachment.Displayname := ‘image1.PNG’;
// DisplayName = Content-ID, HTML tag = <Img src=“cid:image1.PNG”
OMI := UnAssigned;
OL := UnAssigned;

The comment shows what the accompanying HTML tag needs to be. TMS seems to want to rename the image file to something different than the filename when I use the insert picture button to insert the <IMG CID… tag in the HTML. Still have to investigate why / correct that.

Interestingly when the image shows in the Outlook email there is no image file as an attachment in the end result.

Some more useful links:

1 Like