smtpwso2wso2-esbesb

ESB WSO2 How to send an email from esb


I want to make an api for sending some emails from a SMTP server but I don't a user and a password to put in axis2.xml file. So my axis2.xml file looks like this:

    <transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
        <parameter name="mail.smtp.host">email.example.ro</parameter>
        <parameter name="mail.smtp.port">25</parameter>
        <parameter name="mail.smtp.starttls.enable">true</parameter>
        <parameter name="mail.smtp.auth">true</parameter>
        <parameter name="mail.smtp.user"></parameter>
        <parameter name="mail.smtp.password"></parameter>
        <parameter name="mail.smtp.from">email@example.com</parameter>
    </transportSender>

I searched on wso2 docs and I found that I have to do a proxy service for sending emails. Is it possible to do it with just an api? I'm a real newbie with wso2 and my question is what should my proxy service look like and how can I call this service? (should I call it from an api, or what? because I want to send emails based on a value from a database).


Solution

  • @jakub.voves answer is correct. Let me add more details.

    Proxy, APIs, Inbound Endpoints etc are a way to bring external messages into the system.(APIs help you to accept Restful invocation, Proxies allow you to consume SOAP messages, JMS Inbound Endpoints allow you to consume JMS messages from queues/topics) Once you receive the message you can use a combination of mediators to mediate the message.(Message transformations, calling different services etc.) So the mediators within a WSO2 environment are common to all types of services. Hence whatever mediators you use in proxy service can be used in APIs, or in Inbound Endpoints. Other than the mediators WSO2 also provides connectors to extend the functionality of the Server. So in conjunction with Mediators, you can use connectors as well. So in your case either you can use the mailto transport or you can consider using the Email connector. Email sending will look like something below with the connector.

    <email.send configKey="smtpsconnection">
      <from>{json-eval($.from)}</from>
      <to>{json-eval($.to)}</to>
      <subject>{json-eval($.subject)}</subject>
      <content>{json-eval($.content)}</content>
    </email.send>
    

    One additional thing, If your SMTP server doesn't need authentication set the following property to false in axis2.xml.

    <parameter name="mail.smtp.auth">false</parameter>