News: Featured Article: Sending Velocity-based E-Mail with Spring
Matt Raible has written about the JavaMail and Velocity support in the Spring Framework. The article is a short tutorial for setting up Spring's JavaMail support on a PositionManager class, followed by replacing the e-mail's text with a Velocity template. Matt is the author of the upcoming Spring Live book on the framework.
- Posted by: Dion Almaer
- Posted on: April 07 2004 09:20 EDT
Read Matt Raible in Sending Velocity-based E-Mail with Spring
- Featured Article: Sending Velocity-based E-Mail with Spring by Juergen Hoeller on April 09 2004 14:02 EDT
- Article update: Fixed Issues by Matt Raible on April 28 2004 05:05 EDT
- VelocityMail by Sean Sullivan on March 12 2005 15:11 EST
Thanks for writing this tutorial, Matt! Spring's mail support is still among the less-than-perfectly documented parts of the framework, so this is really appreciated :-)
Three notes on further options:
As alternative to specifying a resource loader in the Velocity properties, VelocityEngineFactoryBean supports a "resourceLoaderPath" property, taking any location that's resolvable by the Spring application context (e.g. "/WEB-INF/velocity") as argument. Loading from file resources rather than the classpath allows for hot-reloading of changed templates, e.g. in web apps.
Spring's ApplicationContext abstracts access to file resources to decouple components and configurations from the actual environment. In unit tests, simply load the above with a FileSystemXmlApplicationContext and specify the web app root directory as VM working directory: The resource location will get interpreted as relative file path then, rather than as ServletContext resource.
Spring provides analogous support for FreeMarker 2.3: FreeMarkerConfigurationFactoryBean and FreeMarkerTemplateUtils. So using FreeMarker for generating mail content is as straightforward as using Velocity. FreeMarkerConfigurationFactoryBean also supports a "templateLoaderPath", analogous to VelocityEngineFactoryBean's "resourceLoaderPath".
For more powerful mail options (multipart mails etc), you can use the JavaMailSender interface with JavaMail's MimeMessage class, instead of MailSender with SimpleMailMessage. As a further convenience, Spring provides the MimeMessageHelper class for populating a MimeMessage, also supporting file attachments. See MimeMessageHelper's javadoc for a usage example.
First I have to thank all raibledesigns.com team for providing such good component - DisplayTag and the better than Monster's Struts Resume web application.
My Question is: Is is possible to use DisplayTag as an HTML view to JasperReport?
Keep up the good work
Faisal - you're probably best off asking this question on the < href="http://displaytag.sourceforge.net/mail-lists.html">DisplayTag User</a> mailing list. That being said, I don't think so. The displaytag can (currently) only be used in JSP pages.
I solved the two issues I had in this article: initializing Velocity more than once, and loading templates from the database.