Sun ONE logo     
JavaMail Sample Application

JavaMail Sample Application


This document describes how to use the JavaMail sample application in conjunction with Sun ONE Web Server.

This sample application document contains the following sections:

Overview
 
This simple JavaMail sample application demonstrates use of the JavaMail API. The application uses a servlet to send an e-mail.

Compiling and Assembling the Application


To compile and assemble the sample application, perform the following steps:

  1. Use the following steps to download and set up the JavaMail API 1.3.1 and JavaBeans(TM) Activation Framework 1.0.2

    (a) Download JavaMail API 1.3.1 from http://java.sun.com/products/javamail.
        Extract mail.jar to the <install_root>/bin/https/jar directory.

    (b) Download JavaBeans(TM) Activation Framework 1.0.2 from http://java.sun.com/products/javabeans/glasgow/jaf.html.
        Extract activation.jar to the <install_root>/bin/https/jar directory.

    (c) Open the server.xml file of the web server instance.
        Add the following to the classpathsuffix:
        <install_root>/bin/https/jar/activation.jar
        <install_root>/bin/https/jar/mail.jar

        For example, check the following sample JAVA element (/ws61 is the <install_root>):
       Change it from this:
    <JAVA javahome="/ws61/bin/https/jdk" serverclasspath="/ws61/bin/https/jar/webserv-rt.jar: ${java.home}/lib/tools.jar:/ws61/bin/https/jar/webserv-ext.jar:/ws61/bin/https/jar/webserv-jstl.jar: /ws61/bin/https/jar/ktsearch.jar" classpathsuffix="" envclasspathignored="on" debug="false" debugoptions="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n" dynamicreloadinterval="2"> ........ ........ </JAVA> to this: <JAVA javahome="/ws61/bin/https/jdk" serverclasspath="/ws61/bin/https/jar/webserv-rt.jar:${java.home}/lib/tools.jar: /ws61/bin/https/jar/webserv-ext.jar:/ws61/bin/https/jar/webserv-jstl.jar: /ws61/bin/https/jar/ktsearch.jar" classpathsuffix="/ws61/bin/https/jar/mail.jar:/ws61/bin/https/jar/activation.jar" envclasspathignored="on" debug="false" debugoptions="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n" dynamicreloadinterval="2"> ........ ........ </JAVA>
    (d) Restart the web server instance.

  2. Make sure the necessary parameters for creating  the JavaMail resource are specified in the build.xml file as follows:

      <!-- ======================================================= -->
      <!--               MAILRESOURCE properties                   -->
      <!-- ======================================================= -->
       <property name="javamail.resource.jndiname" value="mail/Session"/>
       <property name="javamail.resource.host"     value="localhost"/>
       <property name="javamail.resource.user"     value="nobody"/>
       <property name="javamail.resource.from"     value="xyz@foo.com"/>
       <property name="javamail.resource.enabled"  value="true"/> 

  3. Go to <install_root>/plugins/java/samples/webapps/javamail/src and execute the ant command.
    The default target 'default' will be executed to build the WAR file.
  4. Execute the following command to create the mail resource:

       ant create_javamail

    Then restart the web server instance.

    Note: The following values are hard coded. If you want to change them, modify the common.xml file under the <install_root>/plugins/java/samples/webapps directory.

    storeprotocol = imap
    storeprotocolclass = com.sun.mail.imap.IMAPStore
    transportprotocol = smtp
    transportprotocolclass = com.sun.mail.smtp.SMTPTranspor
    t

  5. Deploy the application.

    After you have created the sample application from scratch, you can proceed to Deploying the Sample Application. Step 6 is optional.

  6. To clean the web application project area (optional), execute the following command:

    ant clean

  Deploying the Sample Application

To deploy the sample application, perform the following steps:
  1. Go to the src directory of the sample. For example:
    <install_root>/plugins/java/samples/webapps/javamail/src
     
  2. Run ant using the deploy task, as follows:
    ant deploy
If you want to verify registration of the application, proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
 

Verifying Deployment

As an optional step, you can verify that the application has been registered. Otherwise, proceed directly to Running the Sample Application.

  • Go to the src directory of the sample, as follows:
    <install_root>/plugins/java/samples/webapps/javamail/src
  • Run ant using the deploy task, as follows:
    ant list_apps
    You will see the javamail module displayed as one of the listed components.

    Undeploying the Application

    Go to <install_root>/plugins/java/samples/webapps/javamail/src and execute the following command:

    ant undeploy


    Running the Sample Application



    You can run the application through the following URL:

    http://<Web_Server_hostname>:<port>/javamail/sendmail.jsp


    Copyright © 2003 Sun Microsystems, Inc. All rights reserved.