2
votes

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:

MAIL OK

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 Mail Wrong

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

1
did you set the content type correctly? - Thusitha Thilina Dayaratne
Not sure about implemtation, but method setPayloadXML depends of developers might be expecting that variable in template, just consise short usual string, instead of complex html content. HTML can be harmful that is why is it escaped. - simar
Another possible case. If u use WebUI ManagmentConsole, it is always escape content of editor. I had experience to success time ago, only using manual editing of xml file with proxy description in simple text editor. It has quit simple format no so difficult. - simar
thusitha, in the sequence code you can see the content type <property name="ContentType" scope="axis2" value="text/html" /> i think it is correct because when i use payload with harcoded mail content it works, the problem i have is with variable content - cmarguello

1 Answers

4
votes

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