Mail transport

The inner workings of the mail transport has two parts, the transport sender and the transport listener. The transport listener is a basic email client which will be on a loop checking for new messages for a particular email address. When an email comes in it will be tunneled into the Axis engine.

Mail transport can be used against a generic mail server or it can be used like a mailet. The simple mailet provided with Axis2 will direct any message that is coming to a particular address into the Axis engine. The engine will process the message and will use the Transport sender to send the reply.

To get started on the mail transport you need the following additional jar dependencies on the classpath.

  1. javamail
  2. activation

We use the Geronimo version of these jars to compile but you will need the sun version to run the code. Specificaly we are using geronimo-spec-javamail-[version].jar and geronimo-spec-activation-[version].jar. These will be downloaded by maven when you run the maven build.

Transport Sender

You need to have a mail account to activate the mail functionality. This can either be a generic mail server or you can start up a james mail server. The Mail transport sender can be activated by adding following entry to the axis2.xml file.

  
   <transportSender name="mail" class="org.apache.axis2.transport.mail.MailTransportSender">
        <parameter name="transport.mail.smtp.host" locked="xsd:false">smtp server host</parameter>
        <parameter name="transport.mail.smtp.user" locked="xsd:false">user name</parameter>
        <parameter name="transport.mail.smtp.password" locked="xsd:false">password</parameter>
        <parameter name="transport.mail.smtp.port" locked="xsd:false">Port on the server for pop</parameter>
   </transportSender>
  

Transport Receiver

The mail Listener can be activated by adding the following entry to the axis2.xml file.

   <transportReceiver name="mail" class="org.apache.axis2.transport.mail.SimpleMailListener">
        <parameter name="transport.mail.pop3.host" locked="xsd:false">pop server host</parameter>
        <parameter name="transport.mail.pop3.user" locked="xsd:false">user name</parameter>
        <parameter name="transport.mail.pop3.password" locked="xsd:false">password</parameter>
        <parameter name="transport.mail.pop3.port" locked="xsd:false">Port on the server for smtp</parameter>
        <parameter name="transport.mail.replyToAddress" locked="xsd:false">email address</parameter>
  </transportReceiver>
  

At the Client side if the Mail Listener is needed it is automatically started by Axis2.

Using Mail transport in the Server Side

If the Mail Listener is need to be started as the server it can be done with following command with the all the axis2 jars and the mail dependency jars in the classpath.

java org.apache.axis2.transport.mail.SimpleMailListener repository-directory

Using Mail transport in the Client Side

Following code segment shows how to send a oneway SOAP message using the mail transport, this need the Transport Sender configured.

OMElement payload = ....

MessageSender sender = new MessageSender(serviceContext);
sender.setTo(targetEPR);
sender.setSenderTransport(Constants.TRANSPORT_MAIL);

sender.send(operationName.getLocalPart(), payload);

Configure James as SMTP and POP server

Download the Apache James and start James, connect to the James via telnet for administrator James with the following code

$telnet 127.0.0.1 4555
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
JAMES Remote Administration Tool 2.2.0
Please enter your login and password
Login id:
root
Password:
root
Welcome root. HELP for a list of commands

Add users to James

adduser axis2-server axis2
User axis2-server added
adduser axis2-client axis2
User axis2-client added
Connection closed by foreign host.

Now James is up and running with the accounts

Using the included mail server

The inbuilt mail server can be started from the command line using the following piece of code when all the needed jars are in the class path.

java org.apache.axis2.transport.mail.server.MailServer

The server itself does not need any configuration or tinkering to work. A ConfigurationContext and the ports to operate on are the only details needed. The server will store the mails in memory against the recipient till the recipient pops it from the server. To facilitate the use in *nix environments as a non root user the pop and smtp ports used by default config/test cases are (1024 + 25) and (1024 + 110).