JSON array to Table structure formatting while sending email via Mule 4 JSON array to Table structure formatting while sending email via Mule 4 json json

JSON array to Table structure formatting while sending email via Mule 4


Html Table (Payload)

You can customize your css inside @(). I just kept a sample which can be useful to you

%dw 2.0output application/xml writeDeclaration=false---{    table @(style: "width: 50%; border: 1px solid grey; font-family: Monospace" ): {        tr @(bgcolor: "#6c7ae0",style: "color: white !important; font-size:14px; "): {            th @() : "templateId",            th @() : "houseNumber",            th @() : "dataMigrationSourceId",            th @() : "errorDescription"        },        (payload map (item, index) -> {            tr @(align:"center", style: "color: #666666; font-size:12px; font-weight: 500; width:10%"): {                td @(): item.templateID,                td @(): item.houseNumber,                td @(): item.dataMigrationSourceId,                td @(): item.errorDescription            }        })    }}

Parser Template

I further used Parser template Connector to write the html content because the above table we will be sending as html table embedded in mail.

<html>  <head></head>  <body>    <p>Hello XYZ,</p>    <p>Please find the error report for today's run. </p>    <br />  #[payload]<br /><br /><p>This is an automated mail, please do not reply.</p><br /><p>Thanks and Regards,</p></body></html>

Here payload denotes the html table we created above.

Finally in the mail (Send) connector you can refer this html table as payload in the Content of Body.

Note - Make sure you change the ContentType to text/html in the Body of mail Send connector