This documentation is for WSO2 Application Server version 5.0.0. View documentation for the latest release.

Skip to end of metadata
Go to start of metadata

Sample Introduction

This sample demonstrates how you can use the Mail transport in WSO2 Application Server to invoke Web Services. You can find the sample discussed here in <AS_HOME>/samples/Mail directory.

In this sample, a client sends a message to a mailbox in a mail server and the service listens to that mailbox and receives the message. Before deploying a service which uses the Mail transport, you have to enable transports for receiving and sending messages using <AS_HOME>/repository/conf/axis2/axis.xml file. By default, the Mail transport receiver and sender are disabled.


Mail transport Sender

<transportSender name="mailto">
          <parameter name="mail.smtp.from">[email protected]</parameter>
          <parameter name="mail.smtp.user">synapse.demo.0</parameter>
          <parameter name="mail.smtp.password">mailpassword</parameter>
          <parameter name=""></parameter>
          <parameter name="mail.smtp.port">587</parameter>
          <parameter name="mail.smtp.starttls.enable">true</parameter>
          <parameter name="mail.smtp.auth">true</parameter>

Mail transport Receiver

<transportReceiver name="mailto">


The services.xml of the service should contain the following parameters to receive messages through the mail transport.

<parameter name="transport.mail.Address">[email protected]</parameter>
<parameter name="transport.mail.Protocol">pop3</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name=""></parameter>
<parameter name="mail.pop3.port">995</parameter>
<parameter name="mail.pop3.user">synapse.demo.1</parameter>
<parameter name="mail.pop3.password">mailpassword</parameter>
<parameter name="mail.pop3.socketFactory.class"></parameter>
<parameter name="mail.pop3.socketFactory.fallback">false</parameter>
<parameter name="mail.pop3.socketFactory.port">995</parameter>
<parameter name="transport.mail.ContentType">text/xml</parameter>

You have to set the following parameters to your ServiceClient to receive messages, if your service has In-Out operations.

serviceClient.getAxisService().addParameter("transport.mail.Address", "[email protected]");
serviceClient.getAxisService().addParameter("transport.mail.Protocol", "pop3");
serviceClient.getAxisService().addParameter("transport.PollInterval", "5");
serviceClient.getAxisService().addParameter("", "");
serviceClient.getAxisService().addParameter("mail.pop3.user", "synapse.demo.0");
serviceClient.getAxisService().addParameter("mail.pop3.password", "mailpassword");
serviceClient.getAxisService().addParameter("mail.pop3.port", "995");

serviceClient.getAxisService().addParameter("mail.pop3.socketFactory.class", "");
serviceClient.getAxisService().addParameter("mail.pop3.socketFactory.fallback", "false");
serviceClient.getAxisService().addParameter("mail.pop3.socketFactory.port", "995");
serviceClient.getAxisService().addParameter("transport.mail.ContentType", "text/xml");

Your client axis2.xml file should also contain the transport receiver and sender as explained above.

You can see how above configurations are used in the sample by going through the source code and the configuration files provided in <AS_HOME>/samples/Mail directory.

Building the Service

If the WSO2 Application Server is running, shut down the server. Open <AS_HOME>/repository/conf/axis2/axis2.xml and uncomment "mailto" transportReceiver and transportSender. This sample can be run with the default values set for the parameters.

1. In a command prompt, switch to the sample directory.

For example, cd <AS_HOME>\samples\Mail

2. From there, type ant.

3. This creates the "Mail Test service" (MailTestService.aar file) in the <AS_HOME>/repository/deployment/server/axis2services directory.

If you start the Application Server and access the AS Management Console, you should see the "MailTestService" service under deployed services.

4. Click on the service name in the deployed services page. This will open up the dashboard of the service "MailTestService".

5. Refer to the service's mail transport endpoint under the "Endpoints" section of the dashboard. It should be as follows:

6. You can find the mail transport endpoints in the service's WSDL file as well.You can view the WSDL for the service at:


Running the Client

To run the sample client for the service, go to <AS_HOME>/samples/Mail directory and type:sh (in linux). Check the server console and you will see the message printed from the service on the message receival. Log in the to the [email protected]’ by using the password  ‘mailpassword’, and verify that a mail has been received which has the subject ‘SOAPAction: urn:ping’

  • No labels