JSP Insider - http://www.jspinsider.com

News - Articles/Tutorials/Code/Reviews - JSP/Servlet Hosting Companies - Links

Using JSP with JavaMail

Authored by Jayson Falkner - jayson@jspinsider.com

Interested in learning the JavaMail API and implementing it with JavaServer Pages? Well you have come to the right place. This tutorial covers the basics of the JavaMail API and demonstrates them with JSP. Ultimately this tutorial leads in to building and using a generic JSP tag library for the JavaMail API.

The tutorial requires a basic understanding of JSP, JavaBeans and the JavaMail API. Need to brush up on JSP or JavaBean basics? For help with JSP see our tutorial JSP: The Short Course and Sun's product information page. For more information on JavaBeans see Sun's JavaBean Tutorial. What you need to know about JavaMail is covered here and later in the lesson.

What Is JavaMail?

JavaMail is Sun's API for modeling a mail system. It has pre-built implementations of some of the most popular protocols for mail transfer and provides an easy way to use them. More background is available at Sun's JavaMail product information page and at the official JavaMail faq.

Although JavaMail is one of Sun's APIs, it is not currently included with the standard Java Development Kit. This means you will need to download the JavaMail class files unless you have previously done so. To find the JavaMail API click here. You will also need Sun's JavaBeans Activation Framework (JAF). Sun requires the JAF for several reasons. For this tutorial, however, just know that without it JavaMail will not work. Once you have downloaded everything be sure to allow the Java compiler access to the class files. To do this head on to the installation step of this tutorial.

If you would like to skip ahead to a certain section of this tutorial here are the links.

Installation
Introduction to JavaMail
Try the Code - Sending an Email
How it Works - Sending an Email
Try the Code - Sending a Custom Email
How it Works - Sending a Custom Email
Sending to Multiple Recipients
Try the Code - Sending to Multiple Recipients
How it Works - Sending to Multiple Recipients
FAQ for This Tutorial
Continue on with JSP and JavaMail

Installing JavaMail (next)

Browse all of the JSP Insider source-code.

Questions or comments? Contact support@jspinsider.com.