0N/AThis demo illustrates the use of JavaMail APIs in a 3-tiered web
0N/Aapplication. It must be deployed on a web server that supports
0N/Aservlet and JSP-based web applications (e.g. Tomcat) using at least
0N/AJ2SE 1.3 and Servlet 2.2.
0N/A
0N/A +-----------+ +-----------+ +-----------+
0N/A | IMAP | | | | |
0N/A | Server |<-IMAP->| JavaMail |<-HTTP->| WWW |
0N/A +-----------+ | Web app |--HTML->| Browser |
0N/A | SMTP |<-SMTP->| | | |
0N/A | Server | | | | |
0N/A +-----------+ +-----------+ +-----------+
0N/A
0N/A
0N/AThe JavaMail Web application supports the following functionality:
0N/A * login to an IMAP server
0N/A * list all the messages in the INBOX folder
0N/A * view the selected message
0N/A * compose and send a message
0N/A
0N/AIt is comprised of an HTML document and several Web components
0N/A(servlets, JSP pages and custom tags) and is packaged in a Web
0N/Aarchive with the following contents:
0N/A
0N/A index.html
0N/A login.jsp
0N/A folders.jsp
0N/A messageheaders.jsp
0N/A messagecontent.jsp
0N/A compose.jsp
0N/A send.jsp
0N/A errorpage.jsp
0N/A errordetails.jsp
0N/A logout.jsp
0N/A WEB-INF/
0N/A WEB-INF/classes/
0N/A WEB-INF/classes/demo/AttachmentServlet.class
0N/A WEB-INF/classes/demo/FilterServlet.class
0N/A WEB-INF/classes/demo/MailUserBean.class
0N/A WEB-INF/lib/
0N/A WEB-INF/lib/jtl.jar
0N/A WEB-INF/web.xml
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/AThe collection of .html and .jsp files provide the client-side view
0N/Aof the JavaMail Web application.
0N/A
0N/A index.html
0N/A |
0N/A login.jsp
0N/A |
0N/A folders.jsp
0N/A |
0N/A messageheaders.jsp
0N/A |
0N/A / \
0N/A / \
0N/A compose.jsp messagecontent.jsp
0N/A |
0N/A send.jsp
0N/A
0N/A
0N/AThe WEB-INF/web.xml file contains the web applications deployment
0N/Adescriptor. It is an XML document that contains configuration and
0N/Adeployment information for the application.
0N/A
0N/AAs per the Servlet specification, the WEB-INF/classes directory
0N/Acontains servlet and utility classes used by the web application.
0N/AThe FilterServlet acts as the Controller of the JavaMail Web
0N/Aapplication. All requests are mapped to this servlet. It checks
0N/Ato see that the user is logged in to the server before forwarding the
0N/Arequest to the appropriate JSP page. The AttachmentServlet is used
0N/Ato render non-text attachments and the MailUserBean is a utility class
0N/Aused to maintain information about the mail user.
0N/A
0N/AThe WEB-INF/lib directory (also defined in the Servlet specification)
0N/Acontains the Java archive file for the javamail custom tag library.
0N/A
0N/AThe follow tags are furnished in the javamail tag library:
0N/A
0N/A<javamail:sendmail
0N/A mailuser="mailuserbean"
0N/A [host="hostname"] [port="port"]
0N/A sender="email address" recipient="email address"
0N/A [cc="email address"] [bcc="email address"] [subject="subject"]>
0N/Abody of the message
0N/A</javamail:sendmail>
0N/A
0N/ADescription: Used to send messages.
0N/A
0N/A
0N/A<javamail:message id="messageinfo"
0N/A folder="folder"
0N/A num="message number"/>
0N/A
0N/ADescription: Used to read a single message.
0N/A
0N/A
0N/A<javamail:listmessages id="mailinfobean"
0N/A folder="folder"
0N/A</javamail:listmessages>
0N/A
0N/ADescription: Used to iterate through list of messages. The body of the
0N/Atag is repeated for each message in the list.
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/ABuilding and Packaging the JavaMail Web application
0N/A
0N/AAll source for this demo can be found in the following directories:
0N/A src/classes
0N/A src/docroot
0N/A src/taglib
0N/A
0N/ABuild scripts (build.sh and build.bat) are provided for building and
0N/Apackaging the demo. Before executing the build scripts, be sure that
0N/Athe following are in your CLASSPATH:
0N/A mail.jar the JavaMail jar file
0N/A activation.jar the JAF jar file
0N/A servlet.jar the servlet/JSP jar file
0N/A
0N/AThe following steps are performed when building and packaging the demo.
0N/A
0N/A1. Create a directory named "src/docroot/WEB-INF/classes/demo".
0N/A
0N/A2. Create a directory named "src/docroot/WEB-INF/lib".
0N/A
0N/A3. Compile the files from the "src/classes/demo" directory and add them
0N/A to "src/docroot/WEB-INF/classes/demo".
0N/A
0N/A4. Compile the files from the "src/tablib" directory.
0N/A
0N/A5. Create an archive (jtl.jar) of the taglib classes and add it
0N/A to "src/docroot/WEB-INF/lib".
0N/A
0N/A6. Create a web archive file of the contents of "src/docroot" (and all
0N/A of its sub-directories).
0N/A
0N/A(For a list of the contents of the resulting web archive,
0N/A see the beginning of this document.)
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/AA note on sending mail
0N/A
0N/AIn order to send mail using the JavaMail Web App, it is necessary to identify
0N/Aan SMTP host. This can be accomplished in a couple of ways.
0N/A
0N/A1. Use the TOMCAT_OPTS environment variable.
0N/A
0N/A Add the following to the TOMCAT_OPTS environment variable:
0N/A
0N/A -Dmail.smtp.host=yourSMTPmailservername
0N/A
0N/A Restart your web server.
0N/A
0N/A
0N/A2. Modify the send.jsp file and update the javamail.war file:
0N/A
0N/A Add the following parameter to the <javamail:sendmail> tag:
0N/A
0N/A host="yourSMTPmailservername"
0N/A
0N/A Repackage the javamail.war file to include the modified send.jsp file.