Axis2 Mail Transport and Public Mail Servers

The mail transport that has been written with Axis2 has the capability to connect to public mail servers such as Gmail or Yahoo with ease. Most of these public mail servers allow entities to connect to the server through SSL, and it authenticates the entity.

Date: Thu, 2nd Aug, 2007
Level: Advanced
Reads: 5325 Comments: 0 | Login or register to post comments
Saminda Abeyruwan

WSO2 Inc.

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

 

Hot Topic
Hot
Topic

Google Gadgets are a nice way to develop user interfaces for distributed services. The fact that they can be hosted anywhere over a network, not necessarily in the very portal server they eventually run in makes them re-usable and allows users to quickly...

Mini Banners
WSO2Con 2010
Latest Webinar
In this webinar we'll share the range of concerns we've heard from the industry, and survey some of the new and sometimes subtle types of lock-in associated with cloud technologies.
Wednesday, 8 September, 10.00 AM (PDT)