发送带有表情的电子邮件主题时出错

问题描述 投票:0回答:1

我在发送包含自定义主题和表达式的电子邮件时遇到错误:

enter image description here

并出现以下错误:

while writing Java at 
3| {"DataGenerated" : (now()) as String { format: "dd MMM KK:mm a" } }
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.

3| {"DataGenerated" : (now()) as String { format: "dd MMM KK:mm a" } }
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
  at anonymous::main (line: 3, column: 20)" evaluating expression: "output application/json
---
{"DataGenerated" : (now()) as String { format: "dd MMM KK:mm a" } }".
Element               : mongodbconnectFlow/processors/1 @ datagenerator-api:datagenerator-api.xml:36
Element DSL           : <email:send doc:id="e89769cc-f214-44a7-a772-d4a6f626aada" config-ref="Email_SMTP" fromAddress="[email protected]" subject="#[output application/json
---
{"DataGenerated" : (now()) as String { format: "dd MMM KK:mm a" } }]">

我想将主题设为

"DataGenerated": "07 Aug 01:43 PM"

dataweave mule4
1个回答
0
投票

输出电子邮件主题的对象是没有意义的。除此之外,输出格式 JSON 也不会给出预期的输出。请记住,它在对象键值周围有大括号。

对于主题行,您想要输出一个字符串。为此,使用

application/java
是最有效的方法。只需连接字符串并转义字符串内的双引号即可。

%dw 2.0
output application/java
---
"\"DataGenerated\": \"" ++ (now() as String { format: "dd MMM KK:mm a" } ) ++ "\"" 

输出:

"DataGenerated": "08 Aug 11:23 AM"
© www.soinside.com 2019 - 2024. All rights reserved.