Tuesday, September 6, 2016

How to Send an Email From WSO2 ESB



  1. Configure email transport in <ESB_HOME>/repository/conf/axis2/axis2.xml/axis2.xml (There is transportsender commented out in default axis2.xml. You can uncomment them and change the parameter values as you wanted.)
  2.    
       <transportsender class="org.apache.axis2.transport.mail.MailTransportSender" name="mailto">  
         <parameter name="mail.smtp.host">smtp.gmail.com</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">sender</parameter>  
         <parameter name="mail.smtp.password">password</parameter>  
         <parameter name="mail.smtp.from">sender@gmail.com</parameter>  
       </transportsender>  
       
    
  3. If ESB has already started, restart the server.
  4. Log in to Management console and add below proxy.
  5.    
     <?xml version="1.0" encoding="UTF-8"?>  
     <proxy xmlns="http://ws.apache.org/ns/synapse"  
         name="EmailSender"  
         startOnLoad="true"  
         statistics="disable"  
         trace="disable"  
         transports="https,http">  
       <target>  
        <inSequence>  
          <log/>  
          <send>  
           <endpoint>  
             <address uri="http://www.mocky.io/v2/57cef5e5260000ab0564fefa"/>  
           </endpoint>  
          </send>  
          <property name="messageType"  
               scope="axis2"  
               type="STRING"  
               value="text/html"/>  
          <property name="ContentType" scope="axis2" value="text/html"/>  
          <property name="Subject" scope="transport" value="ESB"/>  
          <property name="OUT_ONLY" value="true"/>  
          <property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>  
          <send>  
           <endpoint>  
             <address uri="mailto:reciever@gmail.com"/>  
           </endpoint>  
          </send>  
        </inSequence>  
        <outSequence/>  
       </target>  
       <description/>  
     </proxy>  
       
    
  6. Invoke the proxy and then you can see a mail in reciever@gmail.com's inbox from sender@gmail.com
Note : If you are using gmail to send above mail, you have to allow external apps access in your google account as mention in here.

No comments:

Post a Comment