Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Create email-based apps with JAMES

The open source JAMES mail server offers the tools to develop email-based applications in Java

When it's not ideal to send users to a Website or to launch a GUI-based application, email-based applications can offer an innovative way for users to communicate with server software. Developers have long recognized the value of sending generated emails to users, but until now they have been unable to listen in response. Traditionally, the developer's best approach for a response from generated email was to have the user click a link in the email, sending him or her to a Website URL.

With an email-based application, a user can send an email to a server; the server can then process that email, making the communication two-way. Email-based interaction offers advantages over sending a user to a Website. First, interaction proceeds even if the user is offline. A user can read her email and, in turn, reply with a series of emails that create an instruction queue for a remote system. Second, under some circumstances a user can respond quicker via an email. If the needed response is simple, an email proves faster than Website interactions because the user stays within her email software.

The Java Apache Mail Enterprise Server (JAMES), an open source effort from the Jakarta Project, allows for custom email processing. With JAMES, developers can process messages from users via email. JAMES offers POP3 (Post Office Protocol) and NNTP (Network News Transport Protocol) support, and may support IMAP (Internet Message Access Protocol) in a future release.

In this article, I present an online scheduling system that uses JAMES to capture users' availability. In the future, the scheduling system may use JAMES to track the validity of email addresses, track unsuccessfully delivered scheduling requests, and otherwise further integrate the Web and email sides of the system.

This article assumes that you know how to send an email using JavaMail. (For a JavaWorld article on JavaMail, read "JavaMail Quick Start.") I focus on how to design the communication flow for an email-based application, how to set up JAMES, and how to process user messages.

Note: You can download this article's source code from Resources.

Plan the interaction

In our scheduling system, buyers look for sellers available to do a small piece of work. In the existing system, buyers use a Website to enter a request that is sent to a group of sellers, generating an email to each seller about the request. Sellers receive the email, click an HTTP link to launch a browser, and view the requests on the Website. Sellers then use the Website to enter their availability status and optional notes about why they are or are not available.

In the new approach, the seller composes an email in reply to the email the scheduling system generates. For the seller, there are only two possible responses: he is either available or unavailable. To make his decision known, the seller will send his reply to one of two special email addresses; depending on the address to which the seller responds, his availability will be apparent.

These special email addresses contain the seller's state and a unique identifier for the request in question. The address's structure looks like this:

Resources