无法强制 String { class: java.lang.String }

Cannot coerce String { class: java.lang.String }

我正在尝试从流中发送电子邮件并将所有电子邮件地址存储在 yaml 文件中,如下所示

# Email
email:
  toEmail: "abc.123@gg.org,def.456@gg.org"
  fromEmail: "ms-dev@gg.org"
  ccAddress: "abc123@gmail.com"

我正在尝试将上述值用于发送电子邮件连接器,例如

<email:send doc:name="Send" doc:id="fd09c56f-eaed-44c4-ab06-aa0417f2fdbf" config-ref="Email_SMTP" subject="Error with SOW integration between D365 and Salesforce " fromAddress='#[p("email.fromEmail")]' toAddresses='#[p("email.toEmail") splitBy ","]' ccAddresses='#[p("email.ccAddress")]'>
            <email:body contentType="text/html">
                <email:content ><![CDATA[#[vars.emailBody]]]></email:content>
            </email:body>
        </email:send>

但是在调试时我得到如下错误

org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
********************************************************************************
Message               : "Cannot coerce String { class: java.lang.String } ("abc123@gmail.com" as String {class: "java.lang.String"}) to Array" evaluating expression: "p("email.ccAddress")".
Element               : salesforce-proc-SendEmail_Flow/processors/1 @ salesforce-proc:salesforce-proc-implementation.xml:566 (Send)
Element DSL           : <email:send doc:name="Send" doc:id="fd09c56f-eaed-44c4-ab06-aa0417f2fdbf" config-ref="Email_SMTP" subject="Error with SOW integration between D365 and Salesforce " fromAddress="#[p("email.fromEmail")]" toAddresses="#[p("email.toEmail") splitBy ","]" ccAddresses="#[p("email.ccAddress")]">
<email:body contentType="text/html">
<email:content><![CDATA[
#[vars.emailBody]
]]></email:content>
</email:body>
</email:send>
Error type            : MULE:EXPRESSION
FlowStack             : at salesforce-proc-SendEmail_Flow(salesforce-proc-SendEmail_Flow/processors/1 @ salesforce-proc:salesforce-proc-implementation.xml:566 (Send))
at listener-flow(listener-flow/errorHandler/0/processors/2 @ salesforce-proc:salesforce-proc-implementation.xml:547 (Flow Reference))\

修复 ccAddresses 错误后,出现以下错误

caf9-11ec-b461-025041000001] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
********************************************************************************
Message               : Error while sending email: Exception reading response
Element               : salesforce-proc-SendEmail_Flow/processors/1 @ salesforce-proc:salesforce-proc-implementation.xml:566 (Send)
Element DSL           : <email:send doc:name="Send" doc:id="fd09c56f-eaed-44c4-ab06-aa0417f2fdbf" config-ref="Email_SMTP" subject="Error with SOW integration between D365 and Salesforce " fromAddress="#[p("email.fromEmail")]" toAddresses="#[p("email.toEmail") splitBy ","]" ccAddresses="#[p("email.ccAddress") splitBy ","]">
<email:body contentType="text/html">
<email:content><![CDATA[
#[vars.emailBody]
]]></email:content>
</email:body>
</email:send>
Error type            : EMAIL:SEND
FlowStack             : at salesforce-proc-SendEmail_Flow(salesforce-proc-SendEmail_Flow/processors/1 @ salesforce-proc:salesforce-proc-implementation.xml:566 (Send))
at listener-flow(listener-flow/errorHandler/0/processors/2 @ salesforce-proc:salesforce-proc-implementation.xml:547 (Flow Reference))

任何人都可以建议我在这里缺少什么。

问题是 ccAddresses 需要一个数组。因为您正在使用表达式来配​​置该属性,所以您需要将字符串值从配置文件显式转换为数组,例如使用 splitBy() 函数,就像您在 toAddresses.[=14= 中所做的那样]

如果您只使用一个地址只需删除表达式并使用属性占位符(ccAddresses="${email.ccAddress}")。