1

I had previously asked a question here. replace-cidimage-refrences-in-email-body The question came about because I am writing a basic email archiver/ archived email viewer.

I had saved the body using

IdMessage.Body.SaveToFile(FileName);

With the CID references in that body replaced with base64-encoded images, the resulting HTML displays in a TWebBrowser component when loaded from a blob field in my database. So I have an email viewer now.

The next requirement is to allow a reply to this email. I've added a TEdit above the TWebBrowser, where the UI user can type their single line reply, and I'm using some code to patch the html body to insert the reply line

Reply := '<p class=MsoPlainText>';
Reply := Reply + edReply.Text + '<br>';
Reply := Reply + '<br>-----Previous Message-----<br><br>';
Reply := Reply + '</p>';

before the first <p class=MsoPlainText in that body. This email, sent via IdSMTP, looks good, but Outlook isn't interested in displaying those inline base64-endoded images at all. I need to go back to where I started with this!

I would much like to do something like this:

When the original message is received, save it entirely using this

IdMessage.SaveToFile(FBasePath + 'raw_' + MessageID + '.html'); // works, and can be read by M$ Word

Then formulate that into a reply

IdMessage.LoadFrom(FBasePath + 'raw_' + MessageID + '.html');
IdMessage.Recipients.EmailAddresses := IdMessage.From.Address;
IdMessage.From.Address := repliersaddress;

But now the question is, how do I add the reply text to this html email.

IdMessage.InsertReply(edReply.Text); // would be great

Thanks

Freddie Bell
  • 2,186
  • 24
  • 43
  • There is no ready made solution for this. You will have to manually extract the base64 images and put them into individual `TIdAttachment...` objects inserted into the `TIdMessage.MessageParts` in the appropriate positions, and update the HTML to replace the images with `cid` references to those attachments, and at your result text as needed. Refer to the [HTML Messages](https://www.indyproject.org/2005/08/17/html-messages/) blog article on Indy's website to help you setup the `MessageParts` layout – Remy Lebeau May 18 '19 at 18:15
  • @RemyLebeau Let me get this straight. Starting with the raw_html, I still have to completely disassemble the email into parts and reassemble it, starting with the reply. This sounds horrendous and will entail a significant coding feat given that many of the incoming emails have a hierarchical structure. Or have I hopefully missed something? – Freddie Bell May 18 '19 at 19:12
  • if you have the original email, then no, you simply load it and append the reply text to the `TIdMessage.Body` or appropriate `TIdText` message part as needed, depending on the layout of the email, per the article I linked to. What I described earlier only applies to your mutilated image-extracted emails. – Remy Lebeau May 19 '19 at 01:59

0 Answers0