First, let me clarify what I mean by the "content". There are several parts of it:
- subject.
- body
- "from" field.
mail.created.subject=Account for {0} has been created.Let's look at the alternate solution using Apache's Velocity.
mail.created.from=support@example.org
mail.created.body=Account with the user ID {0} has been successfully created.\n\n\
Please follow this link to use your account:\n {1}\n\nYour Support Team\nexample.org
First, create a file in Velocity macro, e.g. mail-created.vm with following content:
#set ($subject = "Account for $person.name has been created")Now, load and evaluate the template:
#set ($from = 'support@example.org')
Account with the user ID $person.uid has been successfully created.
Please follow this link to use your account:
$link
Your Support Team
example.org
Context context = new VelocityContext();
context.put("person", new Person("Vilmantas Baranauskas", "vilbara"));
context.put("link", "http://vilbara.blogspot.com/");
Template template = Velocity.getTemplate("src/mail-created.vm");
StringWriter body = new StringWriter();
template.merge(context, body);
String from = String.valueOf(context.get("from"));
String subject = String.valueOf(context.get("subject"));
Compare abilities of Velocity and MessageFormat and you will see the benefits.
You may download a zip file containing this example.
No comments:
Post a Comment