通过 Mule 4 发送电子邮件时将 JSON 数组转换为表结构格式 [英] JSON array to Table structure formatting while sending email via Mule 4

查看:35
本文介绍了通过 Mule 4 发送电子邮件时将 JSON 数组转换为表结构格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以表格格式发送错误报告,需要以电子邮件正文的形式发送.我正在将错误报告构建为 JSON 数组,我需要进行 HTML 转换以将其构建为表格格式.

I have a requirement to send the error report as a tabular format, which needs to be sent as a email body. I am constructing error report as a JSON array and I would need to do the HTML transformation to structure that as table format.

以下是 JSON 数组和电子邮件正文的预期结果.

Below is the JSON array and the expected result as email body.

[ { "templateID": "72", "houseNumber": "SR0000V-test", "dataMigrationSourceId": 2102866, "errorDescription": "Process aborted:CatalogItem not found in Target system!" }, { "templateID": "", "houseNumber": "SR0000V-test", "dataMigrationSourceId": 2102866, "errorDescription": "Process aborted: TemplateID is not present!" } ]

预期的电子邮件正文:

如果不是完全相同的格式,则需要类似于表结构或更易读的格式的结果.有人可以帮我在 Mule 4 中构建这种格式

If not exactly same format, would need the result something similar to the table structure or more readable format. Can some one please help me construct this format in Mule 4

谢谢

推荐答案

Html Table (Payload)

您可以在@() 中自定义您的css.我只是保留了一个对你有用的样本

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

%dw 2.0
output 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
            }
        })
    }
}

解析器模板

我进一步使用解析器模板连接器来编写 html 内容,因为上表我们将作为嵌入在邮件中的 html 表发送.

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>

这里的payload表示我们上面创建的html表.

Here payload denotes the html table we created above.

最后,在邮件(发送)连接器中,您可以将此 html 表作为正文内容中的 payload 引用.

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

注意 - 确保将邮件正文发送连接器中的 ContentType 更改为 text/html

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

这篇关于通过 Mule 4 发送电子邮件时将 JSON 数组转换为表结构格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆