Monday, May 21, 2007

Testing application generated emails with Apache James server

Most of our applications send out emails to customers, different groups of people within the organization etc... Most of these emails were in HTML and had all sorts of fancy formatting in them. It was a pain developing and testing these emails and they took too much developer time.

We needed an easy way to test them locally in developer machines without using an external SMTP server.

The plan was to run a James server in every developer machine which forwarded all the emails it receives to an email account on the same server.

Following were the steps followed to achieve this:


1. Download and Run James Server

Downloaded the latest zip bundle from apache site (ver 2.3.1). Extracted to a folder and executed run.bat in the bin directory to start the server for the first time. This will extract the james.sar file in apps directory to the apps/james directory. Now you will be able to modify the configuration file (config.xml) in apps/james/SAR-INF.


2. Create a local email account.

Open a command window and type telnet localhost 4555. When asked for the user name and password type root for both. Now you will be in the admin console and create a email account by typing adduser test test. This will create an email account named test with the password set to test.


3. Delete remote delivery mailet.

Open up the config.xml and locate the RemoteDelivery mailet section <mailet match="All" class="RemoteDelivery">...</mailet> and remove the tag including all its content.


4. Add a forward mailet to forward all mails

Insert the following mailet in the place where the RemoteDelivery mailet was.
<mailet match="All" class="Forward">
<forwardto>test@localhost</forwardto>
</mailet>


5. Save config.xml and Restart the James Server


Now all emails generated by the application (which is configured to use the SMTP server on localhost) will be handled by the James server running in the local machine and it will forward all emails to the test@localhost email account regardless of recipient addresses in email messages.

You can configure Outlook Express or any other client to read the mails sent to test@localhost.

Don' forget to click the +1 button below if this post was helpful.

6 comments:

Anonymous said...

Thanks, I have long needed something like this and didn't know how to configure it.

Anonymous said...

Hey there,

this one has been working great for me in no time.

Thanks, take care,
Andy.

Anonymous said...

Fantastic tip. Thank you.

Gunnar Hillert said...

Great blog post!! Also works well for Apache James 3.0 - http://hillert.blogspot.com/2011/05/testing-email-notifications-with-apache.html

Annie Monie said...

Properly done, tests are completely scientific. If a fast growth direct mail strategy is your goal, understanding the theory of random sampling is essential. Random sampling and statistical analysis tells us that a truly random sample of 100 is large enough to measure the total population.




email testing

Unknown said...

Is this also supported for apache-james-3.0 beta4 version of apache too.