Reputation: 49
i have a proxy to send email. i receive mailto, subject and body(in html format)
i config axis2.xml add
<messageFormatter class="org.apache.axis2.transport.http.ApplicationXMLFormatter" contentType="text/html"/>
and my sequence that works, send the email, but with a hardcoded body:
<sequence name="SendMailTransportSequence" trace="disable"
xmlns="http://ws.apache.org/ns/synapse">
<property name="messageType" scope="axis2" value="text/html" />
<property name="ContentType" scope="axis2" value="text/html" />
<property name="OUT_ONLY" scope="default" value="true" />
<property name="FORCE_SC_ACCEPTED" scope="axis2" value="true" />
<!-- SUBJECT -->
<property expression="get-property('mail.asunto')" name="Subject"
scope="transport" />
<!-- TO -->
<property expression="get-property('mail.destinatario')" name="uri.var.dest"
scope="default" type="STRING" />
<header expression="fn:concat('mailto:',get-property('uri.var.dest'))"
name="To" scope="default" />
<!-- BODY -->
<script language="js"><![CDATA[
mc.setPayloadXML(<html><h1>this is the title</h1><br/><p>this is the content................</p></html>);
]]></script>
<send />
</sequence>
The mail received:
But when i try to send the body from a property i cant reach it
I try
<script language="js"><![CDATA[
var body = mc.getProperty("mail.cuerpo");
mc.setPayloadXML(<html>{body}</html>);
]]></script>
and try too
<script language="js"><![CDATA[
var body = "<h1>this is the title</h1><br/><p>this is the content................</p>";
mc.setPayloadXML(<html>{body}</html>);
]]></script>
in both cases the content is tried like text
In the other hand, i try to use payload factory with no success:
In this case the content is send like an attachment with noname
<payloadFactory media-type="xml">
<format>
<Body>$1</Body>
</format>
<args>
<arg evaluator="xml" expression="get-property('mail.cuerpo')" />
</args>
</payloadFactory>
and in this case the mail body is received like plain text too
<payloadFactory media-type="xml">
<format>
<ns:text xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:text>
</format>
<args>
<arg evaluator="xml" expression="get-property('mail.cuerpo')" />
</args>
</payloadFactory>
So, what is the correct form to send the email in html format? thanks in advance
Upvotes: 2
Views: 1888
Reputation: 373
in this case you cannot append XML element in text string. so you have to add values with as a XML child. because WSO2 esb use java script rhino. write using E4X .
var nextId = 1234;
var first = "John";
var last = "Smith";
var c = <table>
<tr>
<th>Table header</th>
<th>Table header</th>
</tr>
<tr>
<td>{first}</td>
<td>{last}</td>
</tr>
</table>;
for (i = 0; i < 10; i++) {
c.table += <tr>
<td>{i}</td>
<td>{i}</td>
</tr>;
}
mc.setPayloadXML(c);
hope you can get idea from above code. if you want to know more .please refer this link .E4X Quick Start Guide
Upvotes: 4