How to use mail transport in ESB to convert the SOAP message to a plain text mail

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Heshan Suriyaarachchi
  • 22 Dec, 2009

Imagine a scenario where you are using the mail transport in WSO2 ESB. You need to convert the SOAP message to a plain text mail(without any XML in it). This Knowledge Base article is written to address it.

Following steps will guide you to get your scenario up and running.

1) Download a distribution of the WSO2 ESB [1].

2) Extract the zip file. The folder created (wso2esb-2.1.1) will be referred as ESB_HOME.

3) Uncomment the mail TransportSender and TransportReceiver from axis2.xml
ie. ESB_HOME/conf/axis2.xml

<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
<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>
<parameter name="mail.smtp.user">synapse.demo.0</parameter>
<parameter name="mail.smtp.password">mailpassword</parameter>
<parameter name="mail.smtp.from">[email protected]</parameter>
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.MailTransportListener">

4) Add the following line to axis2.xml's MessageFormatters.

<messageFormatter contentType="text/plain" class="org.apache.axis2.format.PlainTextFormatter"/>

5) Build the SimpleStockQuote service (which is residing inside the samples).
ie. ESB_HOME/samples/axis2Server/src/SimpleStockQuoteService

6) Run sample axis2Server.

7) Go to the ESB_HOME/bin and run the script which starts wso2server.
eg. wso2server.bat for windows environments for linux environments

8) Then the server will be started. You can access the management console using the following URL [2].

9) Log into the Mangement Console using following credentials.
      username: admin
      password: admin

10) Create a proxy service using the following proxy configuration.

<!-- Using the mail transport -->
<definitions xmlns="">
<proxy name="StockQuoteProxy" transports="mailto">

    <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">application/xml</parameter>

            <property name="senderAddress" expression="get-property('transport', 'From')"/>
            <log level="full">
                <property name="Sender Address" expression="get-property('senderAddress')"/>
                    <address uri="https://localhost:9000/services/SimpleStockQuoteService"/>
            <property name="Subject" value="Custom Subject for Response" scope="transport"/>
      <property name="messageType" value="text/plain" scope="axis2-client"/>
    <script language="js"><![CDATA[
              mc.setPayloadXML(<ns:text xmlns:ns="">Plain text received!</ns:text>);
            <header name="To" expression="fn:concat('mailto:', get-property('senderAddress'))"/>
            <log level="full">
                <property name="message" value="Response message"/>
                <property name="Sender Address" expression="get-property('senderAddress')"/>
    <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>

11) Send an email to [email protected].

12) You will receive the response in plain text.

Additional Help

ESB documentation -

ESB features -

Mailing lists -

Library -


[1] -

[2] - https://<host>:<port>/carbon/


Heshan Suriyaarachchi, Software Engineer, WSO2 Inc. heshan at wso2 dot com