|Home > Documentation > User's guide > Sample Applications > sendmail - Using Geronimo's Default JavaMail Session|
This article describes how to install a typical mail system, and access it from a simple web application to provide a server based email client. It does not go into details about how to create a configure the mail system itself.
This sample requires that you have an smtp server running. The real value in the sample is to demonstrate how to configure the mail session and connect to it to send a message. If you already have an smtp server configured and running then you can skip this step. However, if you don't, then Apache JAMES is a easy one to use for the test.
1. Download Apache Java Apache Mail Enterprise System (JAMES) from: http://james.apache.org/download.cgi, remember that JAMES support IBM JDK from v3.x.
2. Unzip/untar file.
3. Run JAMES by executing: \james-2.3.1\bin\run.bat. You should see something like this:
For MAC OSX and possibly other unix based systems James must be run under the super user to have authorization to leverage the designated ports.
4. Make sure Geronimo JavaMail module is started:
You can configure the SMTP transport's host and port by overriding the values of the SMTPTransport GBean attrbitues. For our test we will use the default. This will allow us to connect to JAMES running in localhost and using port 25 (the default SMTP port).
Create a simple webapp containing the following files:
geronimo-web.xml: This deployable is using Geronimo 2.0's JavaMail component, so it needs to specify where to look. It does this under the <dependencies> tag. As Geronimo changes, these paths need to be changed accordingly to ensure that it refers to the same things. Under the <resource-ref> element, it is referring to a JavaMail session. This is what allows the developer to reference resources that resides on the server. The <ref-name> element is used in the web.xml so the two must be consistent. The <resource-link> element specifies the default Geronimo mail session.
Download the sendmail application from the following link:
After decompressing the given file, the sendmail directory will be created.
Please reference Samples General Information for information on obtaining and building the source for this and other samples
The sendmail folder will already contain an ear file ready to be deployed. However, you can still play with the source and build it yourself.
Use a command prompt to navigate into the sendmail directory and just give mvn install site command to build. It will overwrite the sendmail-ear-2.0-SNAPSHOT.ear under the sendmail folder. Any dependency on specific versions of javamail may be edited in the geronimo-web.xml deployment plan in sendmail-war/src/main.webapp/WEB-INF/geronimo-web.xml.
5. Test send mail webapp by going to: http://localhost:8080/sendmail
Fill up the form (From, To, Subject, Message fields) and click 'Send' button. You should get a similar message if the mail was sent successfully: