Gunnar Hillert is a Member of Technical Staff (MTS) at SpringSource, a division of VMware. He is a core committer for the Spring Integration project, and also contributes to the Cloud Foundry project. Additionally, Gunnar heads the Atlanta Java Users Group and is co-organizer for the DevNexus developer conference. Gunnar has posted 12 posts at DZone. You can read more from them at their website. View Full User Profile

Testing Email Notifications with Apache James 3.0

  • submit to reddit

On windows machines I have been using Mailster for testing email notifications. Unfortunately, I had issues with Mailster in the past running on non-Windows machines. Thus, on Mac I have been using a local Postfix instance, which forwarded email to dedicated (real) mailboxes. But, it involved a bit of customization and ultimately I had to "know" to which mailboxes I wanted to send notifications to.

However, ideally I don't really care about email addresses. Instead I typically want to verify that the format and layout of the generated emails are good, be it text emails ort Html emails. Ultimately, it would be nice, if for testing, all notification sent ended up in ONE mailbox for development testing purposes.

Enter Apache James. Not long ago I came across this wonderful blog posting below about using Apache James 2.x in order to test application email notifications:

IT is amazing to see that this is pretty much the only dedicated blog posting on the internet regarding a seemingly very common issue. You would think that almost every serious enterprise application has to sent out email notifications, and be it solely for the "forgot password" feature. What is so fantastic about using Apache James, is that it allows you to test Email notifications, while sitting on a plane with no internet in sight. Just run everything locally.

Anyway, the steps illustrated in the blog above also work nicely for James 3.0 (currently milestone 2). What is pretty cool about Apache James is that it is now Spring-based :-)

Here are the simple steps to get things set up for Apache James 3.0:

  • Download Apache James 3.0
  • Unzip the downloaded archive
  • Edit mailetcontainer.xml in directory /conf/
  • Search for "<processor name="transport">"
  • Replace the entire element that starts with "<mailet match="All" class="RemoteDelivery">" with: "<mailet match="All" class="Forward">    <forwardto>test@localhost</forwardto></mailet>"
  • Startup Apache James 3.0 using sudo /bin/ (Sudo is needed for local permissions)
  • Connect via Telnet to Apache James using:  telnet localhost 4555 (User: root password: root)
  • Type: adduser test test <return>
  • Setup Thunderbird (or your favority email application)

I hope this gives you enough starting points for setting up email notification testing. Please leave comments  if you see areas I can improve upon. Onward...



Published at DZone with permission of its author, Gunnar Hillert.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Tomasz Nurkiewicz replied on Wed, 2012/01/04 - 12:57pm

For more low-level testing (e.g. in JUnit) I successfully used greenmail.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.