tags:

views:

645

answers:

3

Is there a way to send a MIME email in which the body of the email is derived from a JSP? I need to send an email with Javamail which contains a table and I figure it would be convenient if I could use a JSP to do all the formatting and layout.

+1  A: 

To do so I think you'd basically have to have a Tomcat (or equivalent) server running and, while you're constructing your email, send a request to the server to invoke your JSP, which would then send back the contents of the email (or the HTML part of the email) as the response. It doesn't seem very elegant, though.

You'd probably be better off with a separate templating system. Here's an interesting-looking answer from a related question.

(shameless plug: I happen to like Clearsilver as a template system, if you happen to be on UNIX/Linux)

David Zaslavsky
+1  A: 

That's kind of tricky. I would suggest you to use Velocity instead.

It is somehow similar to JSP, but it was built to run standalone.

Unfortunately I don't have many resources to where I can redirect you.

Here is one that may look interesting:

http://www.martinfowler.com/bliki/JRubyVelocity.html

OscarRyz
+1  A: 

In this thread, Suggestions for Java Email Templating, a pal Jack Leow is telling how he did that using JSP/Servlet. That might be of any help.

Adeel Ansari