Seeya K
Seeya K

Reputation: 1331

Creating a template in java code for sending emails

My application requires sending an email. I have created a form which when submitted sends email to the required mail id. I am able to successfully send mails. Now I want to create a standard template for sending mails using tokens. Wherever I want to values to be included I should be able to send them using variables. Right now I am sending it as a String.

Is using StringTokenizer helpful? Or is there any other way?

I want to include it in my action class..

Upvotes: 1

Views: 5135

Answers (2)

Makoto
Makoto

Reputation: 106470

Freemarker is an excellent template engine, and it's well suited to generating e-mail content. It has a slight learning curve, but you'll be able to use real variables (like a template should allow you to do) instead of putting everything into a StringTokenizer.

Upvotes: 2

Bhushan Bhangale
Bhushan Bhangale

Reputation: 10987

I would suggest you use Velocity template for your mail. See here http://velocity.apache.org/

In this you have to create a template file where you write whatever text format you need along with placeholders. Using the velocity api you load the template file and pass the placeholders. You can also do dynamic stuff in the template file e.g. looping etc.

Upvotes: 0

Related Questions