Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Javamail API, Exercises

Unit: Javamail
Topic: Send mail using the Javamail API

At the conclusion of this exercise, you will be able to:


• Send an e-mail using the Javamail API.

1. Development Objectives
Creating a J2EE Project and use the Javamail API to send an e-mail message. The
J2EE Project will contain an EAR application and a WAR application. The Web
Application will have a Servlet which will make use of the Javamail API Classes
to send an e-mail message to a SMTP Server. The Web Project also contains a
HTML form used to get the user input for receiver’s e-mail address, Subject and
Message Text.

2. Prerequisites
2-1 You have configured the Java mail client service tab in the Visual
Administrator and have set the SMTP Server and sender’s details. (It is
necessary to restart the server once the java mail client service properties
are changed)
2-2 You have launched the Netweaver Developer Studio.
2-3 You have selected the J2EE perspective.

3. Exercise Guide

3-1 Open the project template in the exercise directory called


InitialProject_Javamail.
3-2 Setup classpath – Add mail.jar to the classpath
3-3 Add code to the doGet method of the servlet
3-3-1 Obtain JNDI Context
3-3-2 Lookup a Javamail Session
3-3-3 Check the SMTP Server and sender’s details and print them to
the browser.
3-3-4 Create a message and set the details (Sender’s name,
Recipient’s name, Subject, Body).
3-3-5 Send the mail and print the response to the browser.

4. Deploying the Application


4-1 Right Click on the JavamailProjectWAR Project and “Choose Build Web
Archive”.
4-2 Right Click on the JavamailProjectEAR Project and “Choose Build
Application Archive”.
4-3 Right Click on the JavamailProjectEAR.ear file and “Choose Deploy to J2EE
Engine”

5. Testing the Application


Open Web Browser and Navigate to this URL http://localhost:<http-
port>/Javamail/SendMail.html

Enter the details on the form and hit Ok to send the mail.

You might also like