Generate HTML e-mail with embedded images in Delphi

Generate HTML e-mail with embedded images in Delphi

Anyone know of a good example of generating HTML e-mail with embedded images and an alternate text part? I need to generate some tabular reports in HTML and would like to embed logos and other images.
I believe Indy can do this with some work, but I was hoping someone could point me to a good example as a starting point. I am open to using libraries other than Indy and commercial solutions provided source is available. Quality and time to implement is more important than cost. The solution also needs to support SMTP based delivery to a mail exchanger.
The other item on my wish list is to be able to leverage FastReports, TRichView or similar tool to generate the HTML message content. There are HTML output filters available for both, but I have not had the opportunity to do any testing. Any feedback on this subject would be appreciated.
Thanks in advance!
David

Solutions/Answers:

Solution 1:

Read the following articles on Indy’s website, they explain the proper way to populate a TIdMesaage for HTML:

HTML Messages

New HTML Message Builder class

Solution 2:

These days I use Clever Component’s email client, though not free.

The TurboPower Internet (OpenSource) controls worked great for me in the past.

Solution 3:

function data64(const filename:string): ansistring;
// uses Classes, IdGlobalProtocols, EncdDecd;
const
  crlf = #13#10;
begin
  result := '';
  with TIdMimeTable.Create do
  try
    result := 'data:'
      + GetFileMIMEType(filename) + ';';
  finally
    Free;
  end;
  with TMemoryStream.Create do
  try
    LoadFromFile(filename);
    result := result + 'base64,' + crlf
      + EncodeBase64(Memory,Size);
  finally
    Free;
  end;
end;

Solution 4:

We tried this years ago with Indy and embedded cid: images like this:
https://forums.codegear.com/thread.jspa?threadID=17473

Related:  GMail appearing to ignore Reply-To

We never got it stable, each time there was another mail reader that barfed (if we got it working in Outlook, then Thunderbird didn’t accept it, or Outlook Express, or, etc, etc).

In the end we did it with .NET using AspNetEmail and it worked like a charm.

–jeroen

Solution 5:

It all depends on how many different remote mail clients you have to be able to support. I believe that the well-known Delphi libraries which support SMTP/Mime will do a reasonable job, but they may leave you with support problems when one of your mail users finds that their recipient cannot see a properly formatted e-mail.

I recommend visiting Jacob Palme’s site which will give you an idea of some of the problems that you may encounter. It is a little out-of-date, perhaps, but in summary, however you build and send your complex MIME e-mail, you will encounter one or more mail clients which cannot handle the syntax properly. The site also has links to some useful examples of constructions which you can examine and test.

I do not mean to imply that you have to roll your own logic as we did: a good packaged solution will probably be successful in the great majority of cases. We wrote our own Delphi code to handle this some years ago, so I will leave it for others to give you up-to-date information about what is on the shelf now.

References

Related:  Sending Multipart html emails which contain embedded images