Installing a Local Mailserver with Liferay

Posted on

For internal development on Liferay, it may be useful to install a local mail server in order to test mail functionality for things like out-of-the-box forms and Kaleo workflows. It is possible to configure Liferay to use an external mail provider like Gmail , but many corporate networks disallow SMTP traffic or block certain ports. In such cases, a local mail server provides a self-contained environment to test mail functionality and email formatting.

Download and Install Apache James

Download the latest version of Apache James. Version 2.3.2 is the latest stable version and the following instructions assume this version rather than the 3.0 beta where the command-line interface has been streamlined.
The package appropriate for your system can be found at http://james.apache.org/download.cgi#Apache_James_Server. For Windows, select the “Binary (ZIP Format)” link.
Step 1 Download James
Unzip the files to C:apache-james-2.3.2 or the directory of your choosing.

Edit Mailserver Configuration

Apache James handles much of its functionality through mailets, which are described as email processing agents. Basically, they’re plugins that are compatible with any mail server that is a mailet container. In this case, we’re interested in the mailet that sends out email and changing the configuration to loop back to the same computer.
Open config.xml in C:apache-james-2.3.2appsjamesSAR-INF (mailetcontainer.xml in directory /conf/ if you’re using James 3.0).
Find the RemoteDelivery mailet entry and delete it entirely from the configuration (that is, everything from to since you will otherwise have malformed XML and James will fail to start).
Step 2 Configure James
In place of the deleted entry, add the following:

    <mailet match="All" class="Forward">
        <forwardto>test@localhost</forwardto>
    </mailet>

Create a local email account

The final step to configure James is to create an email address to send mail to. The address is completely arbitrary and you can create as many addresses as you like.
First start up the mailserver and verify that it’s started successfully. Next, open a command window and type:

telnet localhost 4555

Step 3b Telnet
If you you’re running Windows and don’t have telnet installed, you can easily do so by opening Control Panel and selecting Programs and Features (for Windows 7). You can then choose “Turn Windows features on or off” and checking “Telnet client”.
Step 3a Telnet for Windows
A prompt for the user name will appear and, unless you’ve changed the configuration, use “root” and the same for the password. You will be able to create a user to correspond to the email you entered in your configuration file by typing:

adduser test test

This will create an email account named test with the password set to test.
Step 3c Add User

Configure Liferay with Local Email Settings

Go to the Liferay Control Panel at https://localhost:8080/group/control_panel/
Select Server Administration from the left menu under the Server section and choose the Mail tab
Step 4 Liferay Control Panel 2
Make sure the following values are set in that section:

  • Incoming POP Server set to localhost and port to 110
  • Username and password set to the local server defaults (both should be “root”)
  • Outgoing SMTP Server set to localhost and port to 25
  • Username and password set to the local server defaults (both should be “root”)

Check Your Configuration

You should be able to test your settings by performing an action in the Liferay portal that sends an email. The “Forgot password” functionality with the default Sign In portlet that ships with Liferay is a nice and quick example, requiring only that you have a user configured with the test@test.com email you set up. If all goes successfully, you should see the email from Liferay pop up in the mail spool in James (a Repository.FileStreamStore file) along with a matching internal file (Repository.FileObjectStore).
Step 5 Mail Spool

Set Up a Mail Client

If you just want to see the raw emails and verify that mails are being sent, you don’t need to actually set up an email client. However, in order to view emails and to ensure they’re properly formatted, you may wish to install a client like Thunderbird to simplify things.
Download Thunderbird
Run the installer and open the client
With the New Account Wizard, skip creating a new email and use an existing email.
Step 6a Thunderbird Account
Then select Continue. Thunderbird will attempt to look up settings and fail. Use the default entries with localhost as the Server hostname and the correct port numbers.
Step 6b Thunderbird Account

Accept the warning about security since I think we can trust our local mailserver and don’t want to try to set up .
Select the newly created account and Get mail. You should see the test email(s) in the mail spool download to the client.
Step 6c Thunderbird Email

Additional References and Resources

Setting up Apache James 2.3.2 with a test mailer in Java
Setting up Apache James 3.0 and Thunderbird
Configuring Liferay to use Gmail
More information on Mailets in Apache James


Leave a Reply

Your email address will not be published. Required fields are marked *