Email Templates with XML

This is for our software team:

One feature that seems to eventually creep into every web application is the ability to send email. Generally, it’s a very specific kind of email, like a password reminder, welcome message, order confirmation, or receipt. Despite the fact that the content of these emails differs from application to application, the process of sending email rarely changes. You construct a message, give it to the mail server, and it gets delivered.

One alternative approach is to use XML for the email templates, and that’s the approach I’m going to discuss in this article. XML provides great flexibility in how you structure your templates and does not have the same strict formatting rules as property files do, so it’s easier to maintain large strings. The main downside is that XML files can be trickier to deal with than property files. With a property file, it’s easy to load the files and it’s easy to access the properties once they’ve been loaded. On the other hand, it takes more work to load the XML file and process it using one of the many XML processing libraries provided for use with Java.

Published by

Rajesh Jain

An Entrepreneur based in Mumbai, India.