In one of my previous blogs, I have explained how we can send emails using WSO2 ESB, in this post I am going to explain how we receive emails to WSO2 ESB, so that you can collect data from in coming emails and do some processing and send them to data storage or any other end point.
Before we start ESB server, you need to enable mail transport listeners in ESB. In order to do that you need to go to WSO2_ESB_HOME/repository/conf/axis2/axis2.xml and un comment the following.
Then start the server.
Creating the proxy service
To create the proxy, go to add -> Proxy service -> Custom Proxy service. There we'l give the name as MyMailProzy.
And you need to give set of service parameters as listed below.
<parameter name="mail.pop3.host">pop.gmail.com</parameter>
<parameter name="mail.pop3.password">wso2mail</parameter>
<parameter name="mail.pop3.user">wso2esb.mail</parameter>
<parameter name="mail.pop3.socketFactory.port">995</parameter>
<parameter name="transport.mail.ContentType">text/plain</parameter>
<parameter name="mail.pop3.port">995</parameter>
<parameter name="mail.pop3.socketFactory.fallback">false</parameter>
<parameter name="transport.mail.Address">wso2esb.mail@gmail.com</parameter>
<parameter name="transport.mail.Protocol">pop3</parameter>
<parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
Before we start ESB server, you need to enable mail transport listeners in ESB. In order to do that you need to go to WSO2_ESB_HOME/repository/conf/axis2/axis2.xml and un comment the following.
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.MailTransportListener" />
Then start the server.
Creating the proxy service
To create the proxy, go to add -> Proxy service -> Custom Proxy service. There we'l give the name as MyMailProzy.
And you need to give set of service parameters as listed below.
<parameter name="transport.PollInterval">5</parameter>
<parameter name="mail.pop3.host">pop.gmail.com</parameter>
<parameter name="mail.pop3.password">wso2mail</parameter>
<parameter name="mail.pop3.user">wso2esb.mail</parameter>
<parameter name="mail.pop3.socketFactory.port">995</parameter>
<parameter name="transport.mail.ContentType">text/plain</parameter>
<parameter name="mail.pop3.port">995</parameter>
<parameter name="mail.pop3.socketFactory.fallback">false</parameter>
<parameter name="transport.mail.Address">wso2esb.mail@gmail.com</parameter>
<parameter name="transport.mail.Protocol">pop3</parameter>
<parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
And also under Transport Settings you need to enable mailto transport as shown in the below diagram.
Click on next and we will configure the in sequence.
There we will log the sender's email address by getting the sender email address to a property from the transports (get-property('transport', 'From')) and then using log mediator to log it
<inSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="senderAddress" expression="get-property('transport', 'From')" scope="default" type="STRING"/>
<log level="full">
<property name="Sender Address" expression="get-property('senderAddress')"/>
</log>
<drop/>
</inSequence>
Click on next to configure the out sequence.
In the out sequence we will be having a simple send mediator which will send the response back to the client.
The full ESB Configuration
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="MyMailProzy"
transports="mailto"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="senderAddress" expression="get-property('transport', 'From')"/>
<log level="full">
<property name="Sender Address" expression="get-property('senderAddress')"/>
</log>
<drop/>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<parameter name="mail.pop3.host">pop.gmail.com</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="mail.pop3.password">wso2mail</parameter>
<parameter name="transport.mail.ContentType">text/plain</parameter>
<parameter name="mail.pop3.socketFactory.port">995</parameter>
<parameter name="mail.pop3.user">wso2esb.mail</parameter>
<parameter name="mail.pop3.socketFactory.fallback">false</parameter>
<parameter name="mail.pop3.port">995</parameter>
<parameter name="transport.mail.Address">wso2esb.mail@gmail.com</parameter>
<parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
<parameter name="transport.mail.Protocol">pop3</parameter>
<description/>
</proxy>
Sending the EMAIL
I have used my gmail to send the email to ESB, my to address will be wso2esb.mail@gmail.com, and you can customize your own subject, and the message body.
Once we send the email, the email will be received to ESB, and you will see the following logs
[2013-10-13 09:06:45,038] INFO - LogMediator To: , From: mailto:wso2esb.mail@gmail.com, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: <CAMJOoU667WqnFbx-cCG=hgOy3E2i2qRqKaAUoAcETJE8a-2b+g@mail.gmail.com>, Direction: request, Sender Address = Amani Soysa <amani.soysa@gmail.com>, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">--001a11c233ea18b53d04e8970f15
 Content-Type: text/plain; charset=ISO-8859-1
 
 Sending emails to WSO2 Enterprise Service Bus!!!!
 
 --001a11c233ea18b53d04e8970f15
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 <div dir=3D"ltr">Sending emails to=A0<span style=3D"color:rgb(68,68,68);fon=
 t-family:arial,sans-serif;line-height:16px" >=A0</span><span style=3D"font-w=
eight:bold;color:rgb(68,68,68);font-family:arial,sans-serif;line-height:16p=
x" >WSO2 Enterprise Service Bus!!!!</span>=A0</div>

 --001a11c233ea18b53d04e8970f15--
 </text></soapenv:Body></soapenv:Envelope>
No comments:
Post a Comment