Tuesday, May 24, 2011

Testing Email Notifications with Apache James 3.0

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:


http://livingtao.blogspot.com/2007/05/testing-application-generated-emails.html

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/run.sh (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>
  • ./james-cli.sh -h localhost adddomain localhost
  • ./james-cli.sh -h localhost adduser test@localhost test
  • 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...

5 comments:

J0E said...

Curious, but I get connection refused for port 4555...also, there's no mention of that port within any conf/ files.

J0E said...

Instructions here seemed to work for me:
http://james.apache.org/server/3/quick-start.html

Anonymous said...

Thanks sooo much. Finding a simple and clear tutorial to get a catchall account of james 3 going was tough. You gave me exactly what I need. Thanks for saving me time today

Anonymous said...

thanks. Worked for me. Spent the whole day looking for this.

Anonymous said...

Great Post!

Please any ideas on how to configure apache-james-3.0-beta4 in order to send email to domains (external servers) like gmail, yahoo?

Sending emails locally works perfect.