Discussions

News: Featured Article: Sending Velocity-based E-Mail with Spring

  1. 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.

    Read Matt Raible in Sending Velocity-based E-Mail with Spring

    Threaded Messages (5)

  2. 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:

    1.
    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.

    2.
    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".

    3.
    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.

    Juergen
  3. DisplayTag & JasperReport[ Go to top ]

    Hi Matt,

    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
  4. RE: DisplayTag & JasperReport[ Go to top ]

    Faisal - you're probably best off asking this question on the < href="DisplayTag" rel="nofollow">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.
  5. Article update: Fixed Issues[ Go to top ]

    FYI...

    I solved the two issues I had in this article: initializing Velocity more than once, and loading templates from the database.
  6. VelocityMail[ Go to top ]

    See also:

      http://wiki.apache.org/jakarta-velocity/VelocityMail