Tuesday, October 19, 2010

Send HTML format email from WSO2 ESB

1. Enable mail transport sender and transport listener in the axis2.xml.

<transportSender name="mailto" <transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
<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">synapse.demo.0</parameter>
<parameter name="mail.smtp.password">mailpassword</parameter>
<parameter name="mail.smtp.from">synapse.demo.0@gmail.com</parameter>

<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.MailTransportListener"/>

2. Register the ApplicationXMLFormatter as the formatter for text/html content type in the axis2.xml

&lt:messageFormatter contentType="text/html" class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>

3. In the mediation sequence, set the messageType property as well as the ContentType property to text/html (Setting both parameters is crucial to get this working. The messageType parameter is looked up by the mail transport to select the correct formatter. The other property is used by the formatter to set the right content type on the outgoing message.)

The sample proxy configuration is attached for your reference.

<proxy name="StockQuoteProxy" transports="http" xmlns="http://ws.apache.org/ns/synapse">
<property name="Subject" value="Custom Subject for Response" scope="transport"/>
<property name="messageType" value="text/html" scope="axis2"/>
<property name="ContentType" value="text/html" scope="axis2"/>
<property name="OUT_ONLY" value="true"/>
<script language="js"><![CDATA[
mc.setPayloadXML(<h1>WSO2 ESB Rocks!</h1>);
<log level="full"/>
<address uri="mailto:test@test.com"/>

4. To test the sample, simply send a request to the sample proxy service using the sample Axis2 client. That will send an e-mail with in-line HTML content to the target endpoint.


wso2esb-3.0.0/samples/axis2Client$ ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy


來自大海的心 said...

Hi Heshan,
If the proxy service add "script" mediator, it will appear error
"Unable to modify proxy service :: Unable to modify proxy service: test3-com/sun/phobos/script/javascript/RhinoScriptEngineFactory"

and not to create proxy service.

How can I fix it.

Thank you.

Heshan Suriyaarachchi said...

Hi 來自大海的心,

It's been a long time since I worked with WSO2 ESB and I do not know the current state of development of WSO2 ESB. Can you post this question in WSO2 Forums or Carbon-dev mailing list. You will get an answer for it.


來自大海的心 said...

I got it.

Shivam said...

how did you fix the RHINOSCRIPT PROBLEM?