What is a good html email template system that also correctly displays an alternative to text / plain?

We have a web application that periodically sends users emails. At the moment, we are generating the html version and the text version in the code. However, it is cumbersome to maintain.

Is there a good email template system that can generate both HTML and text versions of email from the same Java template?

Some requirements:

  • any images / icons correctly embedded in mimeparts and properly connected
  • the text version should somewhat resemble the html version - for users who see the text version and spam detectors
  • links should show the url in text version
  • full control (or as much as possible) of layout and style

In case it matters to your answer, we use Struts ... <cough> 1 </cough>.

+4
source share
4 answers

You can use a utility program that converts HTML to Java text (Google for it, for example this one ) by removing tags and converting special HTML characters. However, this will not give you everything you need, especially not formatting (like lists) and links.

Another option is to use XSLT to convert XHTML (write it correctly ...) to text and use an XSLT processor (like Xalan-J or Saxon ) to start it. This is a fairly simple XSLT exercise if your requirements are simple (for example, you don't care about CSS issues).

+2
source

I would also recommend using a template engine. Create two templates: one for the text part and one for the HTML part. Use the include functionality of the template engine so you can reuse literals in both templates.

+2
source

I have successfully used Freemarker templates to prepare txt and html content for emails. If you use Spring, this can make things even easier, since they have all the necessary plumbing. Even without the Spring API, JavaMail is user friendly, so this should not be a problem.

0
source

Take the Apache Speed . I do not know a more powerful template engine.

0
source

All Articles