通过 Mule 4 发送电子邮件时 JSON 数组到 Table 结构格式
JSON array to Table structure formatting while sending email via Mule 4
我有一个要求以表格格式发送错误报告,需要以电子邮件正文形式发送。
我正在将错误报告构建为 JSON 数组,我需要进行 HTML 转换以将其结构化为 table 格式。
下面是 JSON 数组和作为电子邮件正文的预期结果。
[ { "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!" } ]
预期的电子邮件正文:
如果格式不完全相同,则需要类似于 table 结构或更易读格式的结果。
有人可以帮我在 Mule 4
中构建这种格式吗
谢谢
Html Table(有效载荷)
您可以在@() 中自定义您的css。我只是保留了一个对你有用的示例
%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 内容,因为上面的 table 我们将作为 html table 嵌入邮件中。
<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就是我们上面创建的htmltable
最后,在邮件(发送)连接器中,您可以在正文内容中将此 html table 称为 payload。
注意 - 确保在邮件正文发送连接器[=12= 中将 ContentType 更改为 text/html ]
我有一个要求以表格格式发送错误报告,需要以电子邮件正文形式发送。 我正在将错误报告构建为 JSON 数组,我需要进行 HTML 转换以将其结构化为 table 格式。
下面是 JSON 数组和作为电子邮件正文的预期结果。
[ { "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!" } ]
预期的电子邮件正文:
如果格式不完全相同,则需要类似于 table 结构或更易读格式的结果。 有人可以帮我在 Mule 4
中构建这种格式吗谢谢
Html Table(有效载荷)
您可以在@() 中自定义您的css。我只是保留了一个对你有用的示例
%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 内容,因为上面的 table 我们将作为 html table 嵌入邮件中。
<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就是我们上面创建的htmltable
最后,在邮件(发送)连接器中,您可以在正文内容中将此 html table 称为 payload。
注意 - 确保在邮件正文发送连接器[=12= 中将 ContentType 更改为 text/html ]