Thursday, July 9, 2015

Apache's James enterprise e-mail server

The Java Apache Mail Enterprise Server (a.k.a. James) is a 100% pure Java SMTP and POP3 Mail server and NNTP News server designed to be a complete and portable enterprise mail engine solution. James is based on currently available open protocols.


How e-mail works

E-mail is simple, in principle. You construct a message with one or more recipient addresses using a mail user agent (MUA). MUAs come in many forms and include text-based, Web-based, and GUI applications; Microsoft Outlook and Netscape Messenger fall into the last category. Each e-mail client is configured to send mail to a mail transfer agent (MTA) and can be used to poll an MTA to fetch e-mail messages sent to the user's address. To do this, you need an e-mail account on a mail server (technically the MTA) and you can, using standard Internet protocols, either work with the e-mail offline (using POP3) or leave the e-mail on the server (using IMAP). The protocol used to send mail both from the client to the MTA and between MTAs is SMTP (Simple Mail Transfer Protocol).
What really happens between MTAs is only slightly more interesting. E-mail servers rely heavily on DNS and e-mail-specific records called mail transfer (or MX) records. MX records are slightly different from the DNS records used to resolve URLs, containing some additional priority information used to route mail more effectively. I won't delve into those details here, but it's important to understand that DNS is key to routing e-mail successfully and efficiently. James is an MTA, while the JavaMail API provides a framework for an MUA. In this article, we'll use JavaMail to set up a test for our James installation. In the second article in this series, we'll use the James Mailet API to show how you can develop your own James applications.


James design objectives

James was designed to accommodate certain objectives. For example, it is written entirely in the Java language to maximize portability. It was written to be secure and provides a number of features that both protect the server environment itself and provide secure services. James functions as a multithreaded application that takes advantage of many of the benefits available in the Avalon framework. (Avalon is an Apache Jakarta project that features the Phoenix high-performance server infrastructure. Understanding Avalon is useful but not necessary to developing James applications. See the Resources section for more on Avalon.)
James provides a comprehensive set of services, including many that are usually available only in high-end or well-established e-mail servers. These services are primarily implemented using the Matcher and Mailet APIs, which work together to provide e-mail detection and processing capabilities. James supports the standard e-mail protocols (SMTP, POP3, IMAP), along with a few others, using a loosely coupled plug-in design that keeps the messaging framework abstracted from the protocols. This is a powerful idea that may enable James to act as more of a general messaging server in the future or to support alternative messaging protocols such as instant messaging.
The final and most interesting objective delivered by the James design group is the notion of mailets, which provide a component life cycle and container solution for developing e-mail applications. To be sure, it's always been possible to use other MTAs, such as Sendmail, to do this, given that any program can be called and data piped through executables to do the job, but James provides a common, simple API for accomplishing these goals and makes the work easy, thanks to the objects available for manipulation. We'll take a closer look at both the Matcher and Mailet APIs in this article.


Quick Start With James 2.3.1


Make sure your firewall allows the email ports.
Extract the tar file.
Go to the $JAMES_HOME/bin directory.
You may have to change permissions on a few of the shell scripts to get James to run.

chmod 755 $JAMES_HOME/bin/run.sh
chmod 755 $JAMES_HOME/bin/phoenix.sh

At this point, you can run $JAMES_HOME/bin/run.sh, or $JAMES_HOME/bin/phoenix.sh
Running $JAMES_HOME/bin/phoenix.sh gives this:

Usage: $JAMES_HOME/bin/phoenix.sh {start|stop|run|restart|check}

So run

$JAMES_HOME/bin/phoenix.sh start

Let it go for a few minutes.
Then run

$JAMES_HOME/bin/phoenix.sh stop

Configuring James


In order to get James to do something useful, you need to edit the configuration file. This file is $JAMES_HOME/apps/james/SAR-INF/config.xml. You can view the default James configuration file here. To edit this file I used NetBeans, since it has good XML editing features. It has drop-down menus which make it easy to find sub-tags in XML. In this post I use notation for XML tags like this: root/tag/sub-tag/sub-sub-tag.
First, you need to put in the IP address of your DNS servers. On a Unix or Linux machine, you can get this information by looking at /etc/resolf.conf. Put the IP addresses in the config/dnsserver/servers tag, with a “server” tag for each IP address. This will be at lines 758-765 in the default config.xml file.
Next, type the domain names you want James to handle. As far as I know, even if you type in two different domains, like “daydomain.com” and “nightdomain.com”, then any user accounts you put into James will be for both domains. So joe.schmoe@daydomain.com will be the same user as joe.schmoe@nightdomain.com. Put the domains in the config/James/servernames section, with a servername for each domain. This will be lines 54-57 in the default config file.
It is also a good idea to change the password (and maybe the username as well) for the Remote Manager. This is a utility that James uses to manage users. User information can be stored in the database, but so far the documentation for that is not very good. To use Remote Manager, you must log into the server upon which James is running, and telnet to the port specified at config/remotemanager/port, which is line 778 in the default config file. The username and password information is at config/remotemanager/handler/administrator_accounts section, which is at lines 795-799 in the default config file. You may also want to change the server name in the config/remotemanager/handler/helloName section to match what you entered in the config/James/servernames/servername section, but I do not think this is necessary.
It is also good to change the postmaster address, which is line 35 in the default config file, at config/James/postmaster.



Adding Users In James


The default James configuration file has a section for the Remote Manager beginning on line 778, and ending on line 806. To use the Remote Manager, you must telnet to the machine running James on the port specified in the configuration file. By default it is port 4555. The James web site has a page about configuring the Remote Manager, but I was not able to find any information about using it. It is pretty easy to use, but it would be nice if there was a list of the commands. You can get a list of the commands by typing help:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Welcome root. HELP for a list of commands
 help
 Currently implemented commands:
 help                                    display this help
 listusers                               display existing accounts
 countusers                              display the number of existing accounts
 adduser [username] [password]           add a new user
 verify [username]                       verify if specified user exist
 deluser [username]                      delete existing user
 setpassword [username] [password]       sets a user’s password
 setalias [user] [alias]                 locally forwards all email for ‘user’ to ‘alias’
 showalias [username]                    shows a user’s current email alias
 unsetalias [user]                       unsets an alias for ‘user’
 setforwarding [username] [emailaddress] forwards a user’s email to another email address
 showforwarding [username]               shows a user’s current email forwarding
 unsetforwarding [username]              removes a forward
 user [repositoryname]                   change to another user repository
 shutdown                                kills the current JVM (convenient when James is run as a daemon)
 quit                                    close connection
Here is a quick sample session:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
user@machine:/path/to/james$ telnet localhost 4555
 Trying 127.0.0.1…
 Connected to localhost.
 Escape character is ‘^]’.
 JAMES Remote Administration Tool 2.3.1
 Please enter your login and password
 Login id:
 rmusername
 Password:
 rmpassword
 Welcome rmusername. HELP for a list of commands
verify Grumpy
 User Grumpy exists
 adduser genericuser badpassword
 User genericuser added
 verify genericuser
 User genericuser exists
 ^[[A^[[B
 Unknown command
 listusers
 Existing accounts 4
 user: Happy
 user: Grumpy
 user: Sleepy
 user: genericuser
 deluser genericuser
 User genericuser deleted
 listusers
 Existing accounts 3
 user: Happy
 user: Grumpy
 user: Sleepy
 quit
 Bye
 Connection closed by foreign host.

Apache james 3.0 beta4
Add domain :
./james-cli.sh -h localhost -p 9999 adddomain tssdemo.com

Add User :
 ./james-cli.sh -h localhost -p 9999 adduser shivang@tssdemo.com shivang

List Existing User :
./james-cli.sh -h localhost listusers

List Existing Domain :
./james-cli.sh -h localhost listdomains


Reference: