New JSP 2.0 Mailer Taglib
Updated: 2004-08-12
2004-08-12:
Mailer2 has been added to Jakarta Taglibs Sandbox.
A nightly build can be downloaded from the Jakarta site.
Introduction
I did a complete rewrite of the mailer taglib 1.1 to make it a JSP 2.0 mailer taglib.
Features
- Send simple plain text e-mails
- Attach local (file) or external (url) attachments to a message
- Create HTML formatted messages
- Create multipart/alternative HTML and plain text messages
- Save messages in a scope for later use
- Send messages in a background thread for better response times, or directly to get better feedback
- Use JSTL 1.1 EL throughout
- PLAIN or LOGIN SMTP authentication
- Configure server, port, username and password from your web.xml
- Load previously stored messages, or save messages to disk
- S/MIME encrypt and/or sign messages using a Legion of the Bouncy Castle implementation of the S/MIME protocol
Documentation
Download
Why a new taglib?
- JSP 2.0 and JSTL 1.1 allow a more flexible way of configuring and using a taglib
- Create a mailer taglib with JSTL and EL in mind
- No need to use custom EL Evaluators that are unnecessary in a JSP 2.0 environment
- Some features are missing from the 1.1 version: multipart mail, background or foreground sending of mail, better tag lifecycle management, saving messages, configuration, signing and/or encryption of mail messages
- Because it is a maintenance nightmare to maintain both a 1.2 and 2.0 version of the same tag library, a tool is used to create an EL'ified 1.2 version of the original 2.0
Requirements
- JDK 1.4 or higher
- mail.jar and activation.jar from a J2EE 1.4 or JEE 5 distribution
- If you want to use signing and/or encryption:
- For the JSP 2.0 version:
- For the JSP 1.2 version:
How to deploy the examples
- Unzip mailer2.zip
- Copy build.properties.sample to build.properties
- Update build.properties and set the location of the required jar files
- For the 2.0 version:
ant war
- Deploy mailer2.war in your favorite JSP 2.0 container
- For the 1.2 version:
ant war12
- Deploy mailer2_12.war in your favorite JSP 1.2 container
Creating a 1.2 tag library version from a 2.0 version
This package contains a tool that will convert a 2.0 taglib into a 1.2 taglib with the following steps:
- Read the 2.0 taglib JAR file
- Read the TLD file inside the JAR
- For every <tag> in the TLD:
- Create a new class in a new package that ends with "_12" that extends the original 2.0 tag class
- Create new setter methods for the EL for every attribute in the TLD
- Create a
doStartTag() function that evaluates all these EL attributes and stores the result in the corresponding properties in the superclass
- If the tag implements javax.servlet.jsp.tagext.BodyTag, create a function
doAfterBody() that sets the body property with the evaluated version of the BodyContent
This tool is run with ant generate12.
The example JSPs and Javadoc should give a good overview of what is possible and how the library can be used.
Have fun,
Jeroen van Vianen
jeroen at vanvianen dot nl
Home