Introducing the Java Apache Mail Enterprise Server
Enterprises that need a mail server now have Apache James as a powerful option. James is a free, open source mail server that is easy to administer while being powerful and extensible. Kulvir Bhogal makes the introduction and shows you how to set James up to be your enterprise mail server solution.
The Java Apache Mail Enterprise Server (nicknamed James) is a free, Java, open-source SMTP, POP3, and NNTP News Server. In this article, I will show you how James can be set up to be your enterprise mail server solution.
Obtaining James and Meeting Prereqs
At the time this article was written, James was in version 2.1.3. To run this version, you need to have JRE 1.4 installed. (James can be downloaded here.) I assume that you are using James within a Windows environment. However, because James is Java-based, the platform of your choice is limited only by whether or not an appropriate Java Virtual Machine can be found to power James.
Opening Up Ports
To use James as your mail server, you need to open up some TCP ports. By default, the SMTP port that needs to be opened is port 25. Also, a port must be opened for the POP3 protocol. (By default, this is port 110). As you will see later in this article, you can also remotely administer James by using the Remote Manager Service. (By default, this service listens on port 4555.)
To run James, make sure that your JAVA_HOME environment variable points to the JRE 1.4 home directory. Then execute the run.bat script from the bin directory where you extracted James (see Figure 1). When you do this, you should see that James is listening to ports 25 and 110 (for SMTP and POP3 services).
Figure 1 Starting James.
When you first run James, configuration files are created for you. At this point, you have to stop the server to modify the configuration files to get some useful functionality out of James.
You need to teach James to respect the domain for which you’re trying to set up e-mail. To do this, you need to modify the section of the config.xml file (located in the <james-installdir>\apps\james\SAR-INF directory) as follows:
<servernames autodetect="true" autodetectIP="true"> <!-- CONFIRM? --> <servername>localhost</servername> </servernames>
You need to add the DNS namespace for which James will handle mail. For example, suppose that you want to handle mail for bogusdomain.com. The syntax would be the following:
<servernames autodetect="true" autodetectIP="true"> <!-- CONFIRM? --> <servername>localhost</servername> <servername>bogusdomain.com</servername> </servernames>
Note that you simply just can’t start receiving mail for a given domain. The DNS records and Mail Exchanger (MX) records of that domain should point to the IP address that the box running James is associated with. If you’re using a router, your router should redirect port traffic (for example, for SMTP, POP3, and Remote Manager Service requests) from your WAN IP address to the LAN IP address of the machine that’s running James.
Showing James Who’s Boss
You can administer James via its Remote Manager Service. (By default, this service listens to port 4555.) The following syntax can be used to administer James:
telnet localhost 4555
If you’re accessing James remotely, simply replace localhost with the appropriate IP address/hostname.
The default login and password for the Remote Manager Service are root and root, respectively. (You change them in the config.xml file.) Look for the section <administrator_accounts> and modify the section with a secure user name and password combination.
James ships with an embedded help facility that you can access using the HELP command.
Users can be added to James using the following syntax:
adduser [username] [password]
For example, I added the user kulvir with this syntax:
adduser kulvir mypassw0rd
Hooking Up with James
After adding a user, you can test things out by creating an account with your favorite Mail User Agent (MUA) software (for example, Lotus Notes, Microsoft Outlook, and so on). You should consult your product’s documentation about how to go about setting up a mail account. Send a test email to the account you created; if things are set up correctly, you should see an e-mail in your box (see Figure 2).
Mailets and Matchers
Although James is a mail server, it is also a mailet container. Similar to the way J2EE containers power Enterprise Java Beans, James powers mailets. (Mailets are used to process mail, and matchers are used to match mail messages against certain conditions.) James ships with a number of predefined matchers and mailets.
The concepts might best be displayed by example. Let’s say that you want to add the following message footer to each email received by James:
------------------------------------------------ Brought to you courtesy of Apache James
You can use the AddFooter mailet and the “All” matcher to add the footer. Add the following to your config.xml file:
<mailet match="All"> <text> ------------------------------------------------ Brought to you courtesy of Apache James </text> </mailet>
After a restart of James, all mail sent to any email address that James is hosting will have the footer added to the end of the e-mail, as shown in Figure 3.
Figure 3 The footer is dynamically attached to the e-mail.
James has built-in support for the handling of mailing lists, and users can subscribe and unsubscribe to these lists.
To create a list, you must add the following to the config.xml file in the root processor block and above the final mailet block:
With the mailet above, if a sender sends a message to firstname.lastname@example.org, the sender is subscribed. Similarly, if he or she sends a message to email@example.com, he or she is unsubscribed.
Subscribers are stored in a repository, which can be your file system or a database. The following is an example of the syntax that is necessary to define the repository to the file system:
To handle the mail, you must also have the mailet in our config.xml file:
<mailet match=”RecipientIsfirstname.lastname@example.org” class=”AvalonListserv”>
<membersonly> false </membersonly>
<attachmentsallowed> true </attachmentsallowed>
<replytolist> true </replytolist>
With the mailet above, if you send a message to email@example.com, subscribers will receive incoming messages.
Can You Run James as a Windows Service?
Unfortunately, James does not run as a Windows NT/XP service. However, you can use an offering such asJavaService from Alexandria Software to wrap James as a service.
Power in Extensibility
The Apache Software Foundation allows you to create your own custom mailets and matchers. You can learn more about how to create your own mailets and matchers via the James product documentation (as shown in the following Resources section).
James is an open source project of the Apache Software Foundation that has seen much attention by the open source community. The project is under constant development. Future versions promise IMAP capability, which is typically a choice of a larger enterprise. James has a lot more to offer than what I highlighted in this introductory article. You can learn more about the project via the project documentation at the documentation link.
Entry filed under: java.