Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Mailets and Matchers
Using Apache James and JavaMail to implement variable envelope return paths

Apache James is a full-featured SMTP, POP3, and NNTP server built using 100% Java and more importantly it's been designed from the ground up to be a mail application platform

Anyone who's spent any time working on an application that sends e-mails has come across more than his fair share of bounced e-mails. If you actually read the bounced e-mails, you probably noticed that many of them either came from the ISP's error handler (mailer-daemon@isp.com) or from an e-mail address that wasn't on your mailing list. The bounced message may not even have contained a copy of the original message. All of above scenarios make it very hard to figure out who the original message was sent to. Enter Daniel Bernstein, also known as djb, who in 1997, in response to this problem of matching bounced e-mail messages to subscription addresses, wrote a paper describing a technique he called Variable Envelope Return Paths or VERP for short. In the paper, he describes process as:

...each recipient of the message sees a different envelope sender address. When a message to the djb-sos@silverton.berkeley.edu mailing list is sent to God@heaven.af.mil, for example, it has the following envelope sender:

djb-sos-owner-God=heaven.af.mil@silverton.berkeley.edu

If the message bounces, the bounce message will be sent back to djb-sos-owner-God=heaven.af.mil@silverton.berkeley.edu.

If God is forwarding His mail, the bounced message will still go to djb-sos-owner-God=heaven.af.mil@silverton.berkeley.edu. No matter how uninformative the bounced message is, it will display God's subscription address in its envelope.

But you probably noticed that this article isn't only about VERP: Apache James is a full-featured SMTP, POP3, and NNTP server built using 100% Java and more importantly it's been designed from the ground up to be a mail application platform. The James mail application platform makes it a perfect candidate for handling bounced messages using VERP. Similarly, the JavaMail API is a framework for building mail and messaging applications using SMTP and POP3. JavaMail makes it easy to customize the envelope sender address, which means Java developers can use JavaMail on the client and James on the server to build e-mail applications that enables VERP.

This article will describe an example VERP implementation, show how JavaMail can be used to modify the envelope sender address, and then illustrate how James can be used to recognize and process bounced e-mail messages. It's not intended to be an in-depth look at either the Apache James mail server or the JavaMail API. If you're interested in learning more about Apache James, a product review is available on the Sys-Con.com Web site (http://java.sys-con.com/read/38667.htm) and an extensive introduction to Apache James on the IBM developerWorks sit (www-128.ibm.com/developerworks/library/j-james1.html). The JavaMail API can also be reviewed on the Sys-Con.com site: http://java.sys-con.com/read/36545.htm.

VERP and JavaMail
Let's start by looking at the e-mail newsletter that a fictional store called "Javazon" is sending to its customers. The developers at Javazon have been using the JavaMail API to successfully send the newsletter through their mail server using code similar to the example below.

    String sendere-mail = "deals@javazon.com";
    String toe-mail = "ajohnson@cephas.net";
    Properties props = new Properties();

props.put("mail.smtp.host", mailserver);

Session session = Session.getInstance(props, null);

javax.mail.Message m = new MimeMessage(session);

m.setFrom(new InternetAddress(sendere-mail));

m.setSubject("New Deals at Javazon!");
    m.setRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(toe-mail));
m.setContent(content, "text/plain");

Transport.send(m);

The code above will produce an e-mail message with headers that look like this:

Date: Wed, 26 Apr 2006 21:00:21 -0000
From: deals@javazon.com
To: ajohnson@cephas.net
Subject: New Deals at Javazon!

Because they want to be good e-mail citizens, the developers at Javazon use the POP3 functionality in JavaMail to retrieve the e-mails that bounce back to the address specified as 'sendere-mail' in the example above. Unfortunately, many of the bounced e-mails come from daemon accounts (instead of the recipient e-mail address), which makes it difficult to figure out what e-mail address the original message was sent to.

As mentioned at the beginning of this article, the only way to address the bounces that come from daemon accounts is to use VERP, which is a two-part process. The first is relatively simple. An e-mail message, according to the SMTP RFC-821 Section 2, is composed of two parts: an envelope that contains the SMTP source and destination addresses and the message, which consists of the headers and message body. To create a VERP-capable e-mail message, you only need to modify the envelope, which is easily done using the instance of java.util.Properties associated with the javax.mail.Session. Modifying the first example, the developers would end up with this:

    String sendere-mail = "deals@javazon.com";
    String toe-mail = "ajohnson@cephas.net";
String verpFrom = "deals-" + toe-mail.replaceAll("@", "=") + "@javazon.com";
    Properties prop = new Properties();
    props.put("mail.smtp.from", verpFrom);
props.put("mail.smtp.host", mailserver);
    Session session = Session.getInstance(props, null);

javax.mail.Message m = new MimeMessage(session);
m.setFrom(new InternetAddress(sendere-mail));
m.setSubject("New Deals at Javazon!");
    m.setRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(toe-mail));

m.setContent(content, "text/plain");

Transport.send(m);

When executed, this code would create an e-mail message with headers that look like this:

Return-Path: <deals-ajohnson=cephas.net@javazon.com>
Date: Wed, 26 Apr 2006 21:00:21 -0000
From: deals@javazon.com
To: ajohnson@cephas.net
Subject: New Deals at Javazon!

Notice the different "Return Path:" header from the first e-mail? If the e-mail message bounces back to Javazon, it will go to the e-mail address associated with the 'Return Path' header: "deals-ajohnson=cephas.net@javazon.com" rather than "deals@javazon.com." This is where Apache James comes into the picture.

VERP and James
James can be configured and used like any other e-mail server, but its real power comes from the ability it gives Java developers to plug right into the mail-processing pipeline. James enables you to process e-mail messages in the same way you might process HTTP requests that come into servlet containers like Tomcat, but in a more flexible manner. If you want to pre-process (or post-process) HTTP requests in Tomcat, you first create a class that implements the javax.servlet.Filter interface and then you create an entry in your web.xml that matches certain requests to that class. Your configuration might look something like this:

<filter>

<filter-name>myfilter</filter-name>

<filter-class>com.javazon.web.filters.GZipFilter</filter-class>

</filter>
<filter-mapping>

<filter-name>myfilter</filter-name>

<url-pattern>*.jsp</url-pattern>

</filter-mapping>

The servlet container limits how you match requests to a filter: you're limited to pattern matching on the URL. Instead of a <filter> and <filter-mapping>, James gives you a <mailet> made up of two parts: Matchers and Mailets. They're described on the James wiki:

"Matchers are configurable filters which filter mail from a processor pipeline into Mailets based upon fixed or dynamic criteria.

"Mailets are classes that define an action to be performed. This can cover actions as diverse as local delivery, client-side mail filtering, switching mail to a different processor pipeline, aliasing, archiving, list serving, or gateways into external messaging systems."


About Aaron Johnson
Aaron Johnson is a senior software engineer at Jive Software. He lives with his wonderful wife, young son and dog in a Portland, Oregon. You can find out more by reading his blog at http://cephas.net/blog/.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
Citrix has opened up a beta of its CloudStack 3, the first release of the open source cloud platform under the Citrix brand. Citrix acquired the Java-based cloud management last year when it bought Cloud.com. A full production version of the branded stuff is supposed to be avai...
EMC and VMware are going into the cloud business with Atos, the big, publicly owned, Paris-based global IT services firm, intending to take an equity position in Canopy, an end-to-end cloud company Atos is setting up using EMC and VMware technology. The companies said Wednesday...
A Tel Aviv start-up called Porticor that’s just hit the radar says it’s got a way to secure the cloud, any cloud. Fancy that, a trustworthy cloud. And Porticor delivers its data encryption solution to IaaS and PaaS users through the cloud in minutes. Fancy that. It’s supposed...
Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
"The volume of data we're generating now from machines pales in comparison to the volume of data we'll soon generate from our own bodies," says data security expert Dave Asprey. Writing in a Trend Micro blog, Asprey - who is one of the leaders in the emerging Quantified Self move...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News

DALLAS, Feb. 17, 2012 /PRNewswire/ -- Dominion Resources Black Warrior Trust (NYSE: DOM) today an...