I’m renovating a legacy Java Servlet webapp. I’m wondering there is a better way to do email. Right now the app has a giant class for it where most of the verbiage is about concatenating message text with data and the conditions for deciding to do so.
I’m using Spring-MVC is newer parts of the application. I did a quick Google on Spring and Email and it looks like Spring is mostly about abstracting the sending of email itself which I don’t have a problem with. Am I correct?
What I would like is an API/system that will allow me to put message text for individual emails into text files and allow me to insert data into that text via variables. I would also like something that will make the collection of that data and the calculation of conditionals less unwieldy.
Lastly, the app only has about 6 different emails that it sends. I’m looking for system that is QUICK to learn. I don’t need to conquer the email world, I would just like to clean up some messy legacy code.
Is there such a quick to learn email api?
Thanks much in advance for any info
Steve
You can use Spring to compose email messages (see http://static.springsource.org/spring/docs/1.2.x/reference/mail.html), and you can use plain text files with tokens (maybe Apache-style, like ${foo.bar}) and read them in, replace the tokens in code, and set that text to your email message text. As others have suggested you can use a template engine to do that, or you can just use
String.replaceAll().