views:

41

answers:

2

Hello everyone, has anyone a good hint how to send E-Mails from Spring 3 that were created by a view (a jsp)?

(the spring manual describes how to use Velocity as template engine for generating e-mail bodies, but is it also possible to use JSPs instead?)

+1  A: 

JSP programming model is too tightly tied to HTTP request processing, therefore there are no good ways to use JSP as a template engine in different contexts.

axtavt
+1  A: 

I recommend that you use Freemarker instead of JSPs. It is easy to set up and use, and Spring even supplies some utility classes to help with common tasks. (Velocity is another good option.)

JSPs would be fundamentally difficult to use because the compiled JSPs and the JSP engine are full of assumptions that you are generating some kind of servlet response. I wouldn't say that it is impossible to use JSPs ... but you really don't want to go there, I think.

(Actually, here's a rather perverted "solution". Take all of the information you want to include in the email body and encode it as URL query parameters or POST data or something. Then use HttpClient or similar to make a call to an internal HTTP service whose purpose is create an email body using a JSP. Ughh...)

Stephen C