Library

Axis2 Mail Transport and Public Mail Servers

  • By Saminda Abeyruwan
  • 2 Aug, 2007

The following diagram shows how the Axis2 mail transport is configured to connect to the GMAIL mail server, and carry out operations such as SMTP and POP.

 

Pic1

Figure 1 : Participation of client, server, and public mail server

Let's consider the public mail server as GMAIL. There are two parties involved in this communication- client and server. The client has an email address x-client@gmail.com (username: x-client;password: x-client) and the server has an email address x-server@gmail.com (username: x-server;password; x-server). Both the client and the server run on top of the Axis2 platform, which has Axis2.xml files for specifying the configuration of the setup.

x-client wants to send a message to x-server using the Axis2 infrastructure. This message might be subjected to the Web service Quality of Services such as ws-security, ws-reliable messaging, etc.

Introduce the following XML fragments to the client side Axis2.xml

 

<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">

     <parameter name="mail.smtp.host">smtp.gmail.com</parameter>
     <parameter name="mail.smtp.auth">true</parameter>
     <parameter name="mail.smtp.port">465</parameter>
     <parameter name="mail.pop3.socketFactory.port">465</parameter>
     <parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
     <parameter name="mail.pop3.socketFactory.fallback">false</parameter>
     <parameter name="mail.debug">true</parameter>
     
     <parameter name="mail.smtp.user">x-client</parameter>
     <parameter name="transport.mail.smtp.password">x-client</parameter>
     
</transportSender>

<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.SimpleMailListener">
     
     <parameter name="mail.pop3.host">pop.gmail.com</parameter>
     <parameter name="mail.pop3.user">x-client@gmail.com</parameter>
     <parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
     <parameter name="mail.pop3.socketFactory.fallback">false</parameter>
     <parameter name="mail.pop3.port">995</parameter>
     <parameter name="mail.pop3.socketFactory.port">995</parameter>

    <parameter name="transport.mail.pop3.password">x-client</parameter>
    <parameter name="transport.mail.replyToAddress">x-client@gmail.com</parameter>
</transportReceiver>

 

Introduce the following XML fragments to the server side Axis2.xml

 

<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">

     <parameter name="mail.smtp.host">smtp.gmail.com</parameter>
     <parameter name="mail.smtp.auth">true</parameter>
     <parameter name="mail.smtp.port">465</parameter>
     <parameter name="mail.pop3.socketFactory.port">465</parameter>
     <parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
     <parameter name="mail.pop3.socketFactory.fallback">false</parameter>
     <parameter name="mail.debug">true</parameter>
     
     <parameter name="mail.smtp.user">x-server</parameter>
     <parameter name="transport.mail.smtp.password">x-server</parameter>
     
</transportSender>

<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.SimpleMailListener">
     
     <parameter name="mail.pop3.host">pop.gmail.com</parameter>
     <parameter name="mail.pop3.user">x-server@gmail.com</parameter>
     <parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
     <parameter name="mail.pop3.socketFactory.fallback">false</parameter>
     <parameter name="mail.pop3.port">995</parameter>
     <parameter name="mail.pop3.socketFactory.port">995</parameter>

    <parameter name="transport.mail.pop3.password">x-server</parameter>
    <parameter name="transport.mail.replyToAddress">x-server@gmail.com</parameter>
</transportReceiver>

 

Once the Axis2 configuration files have been extended as above, a client can send and receive messages via mail transport by simply using a ServiceClient. Make sure that all the Axis2 jars are in the CLASSPATH

...

   ServiceClient sc = new ServiceClient(configCtx,null);
   Options options = new Options();
   options.setTo(new EndpointReference("mailto:x-server@gmail.com/services/xkms")):
   ...
   OMElement resEle = sc.sendReceive(payload);
   ...
      

Applies To

Axis2/Java Versions : 1.3-SNAPSHOT and 1.2

More Information

http://people.apache.org/~pzf/SMTPBase64Binding.html