views:

624

answers:

5

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

A: 

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

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

Jeroen Pluimers
A: 

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.

frogb
+5  A: 

Read the following articles on Indy's website:

HTML Messages
New HTML Message Builder class

Remy Lebeau - TeamB
The Indy MesssageBuilder seems to be the way to go. The only potential coding issue I see based on the examples is that files are being read from disk. I need to use streams since the data and images lives in a database. I will check the source to see if other methods of adding images are supported and make the necessary adjustments if not.
David Taylor
Using TIdMessage, TIdText and TIdAttachmentMemory you can build the message and attachments using streams.
ajob
TIdMessageBuilderHtml supports using TStream for attachment data that are related to the HTML, such as images. The TIdMessageBuilderHtml.HtmlFiles property has overloaded versions of Add() for filenames and TStream data. Attaching non-related data, however, does not currently support TStream yet.
Remy Lebeau - TeamB
I have updated the TIdCustomMessageBuilder.Attachments property to support TStream data now.
Remy Lebeau - TeamB
@Remy - Thanks, that does the trick. I guess I will need to use the latest code from SVN :)
David Taylor
+1  A: 

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

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

Hein du Plessis
Thanks, I have not looked at their components in quite a few years. Clever Component has certainly become very feature rich, but the price tag is a bit steep unless you really need some of the advanced functionality.
David Taylor
A: 

My two centes. FastReport.Net has also good export filter to MHT. Do not know about FastReport for Delphi.

Merl