Which Java templating system should I use to generate emails?

Which Java templating system should I use to generate emails?

I have a website that uses JSP as its view technology (and Spring MVC underneath). Unfortunately, JSP is just a pain to use for anything that doesn't involve an HTTP session. I would like to be able to occasionally send my users some email, and I want to use something JSP-like to render the email's contents. Technologies I'm aware of include:

  • JSP -- It can be forced to work for this sort of thing, I think. Very worst case, I could request the page from my own webserver and render that into an email (ugh!)
  • Velocity -- I've heard good things about this one, and am leaning towards it.
  • StringTemplate -- Looks okay, but I'm worried that no new releases have come out in a year.

Is there a preferred technology for templating in a Java system? Would folks generally recommend Velocity? Is there a good way to use JSP for more generic tasks?

Resolve JNDI lookups from Spring application context?


Why does calling close() on an InitialContext break JNDI for all future lookups (Glassfish)?
You should go with Velocity.

Configuring Spring based servlet with sysadmin defined properties
It's easy to learn and has a low dependency and implementation footprint, especially when using Spring..
Advantages to adding Spring to Flex
But, if it's just one Use Case, you should stick with the String and unless you have no time for experiments ;).
How do you set cache headers in Spring MVC?

Auto-wiring a List using util schema gives NoSuchBeanDefinitionException

Is it bad practice to put view code in the controller?


When is it appropriate to use an EAR and when should your apps be in WARs?
I used Freemarker a lot for e-mail templating and it worked great and was easy to use..


I have used StringTemplate several times successfully for sending emails.

It is simple and extremely easy to integrate.. The simplicity of StringTemplate makes it straightforward to substitute different parts of the message, for example, subject.

Not sure how to do this with Velocity.. I wouldn't worry about the release frequency -- maybe it is just good enough and doesn't need to be actively developed any more..

88 out of 100 based on 88 user ratings 238 reviews