aspose file tools
The moose likes Servlets and the fly likes Best way to create a dynamic HTML Email from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best way to create a dynamic HTML Email from a servlet" Watch "Best way to create a dynamic HTML Email from a servlet" New topic
Author

Best way to create a dynamic HTML Email from a servlet

Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3358
    
  60

Assume a scenario that you need to send a dynamic email from a web application, something like a confirmation email for the user registration. It is easy to create that email, if it is a small email having only few lines. We can create it as a String value, and then send it via JavaMail or any other api. But what if it is a large email having hundreds of html tags with a large content? What is the best way to create it?

I think it is best if we can create that email as a JSP. So we can capture the output stream of that JSP using filters, and assign it to a String variable. But do you think that it is a good practice for here?

Devaka.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

A templating technology (such as Velocity) might be a good bet.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3358
    
  60

Paul Sturrock wrote:A templating technology (such as Velocity) might be a good bet.


If I tell you the truth, I didn't know about the 'templating technology' before. Thank you Paul for letting me know about it.

Devaka.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62123
    
  68

Well, JSP is a templating technology -- which is probably why your initial reaction was to try and use it. But I agree with Paul, using a templating engine would be more striaght-forward than trying to subvert JSP for that usage.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3358
    
  60

Bear is right. I wondered about a 'templating technology', or something else other than JSP. Because it sounds inappropriate when JSP is subverted to that usage.

Thanks,

Devaka.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Best way to create a dynamic HTML Email from a servlet