Search code examples
javamuleesbanypoint-studio

Mule ESB - SMTP Subject from a variable


I'm working on a flow to send an attached file to a mail.

<smtp:outbound-endpoint host="${instance.smtp.host}" port="${instance.smtp.port}" user="${instance.smtp.user}" password="${instance.smtp.password}" responseTimeout="10000" doc:name="SMTP" connector-ref="SMTP" from="${instance.smtp.account}"  to="${instance.smtp.user}" subject="Transaction ID #[flowVars.transactionId]"/>

Everything is working well, I already have tested my flow and the mails are arriving to the specified mail address, however, I'm trying to modify the subject dynamically, using a value stored in a variable, and then the problem appears, seems like it's not possible to use my expression to set the subject's mail.

subject="Transaction ID #[flowVars.transactionId]"

This is the error I'm getting.

Root Exception stack trace:

[Error: unresolvable property or identifier: Transaction] [Near : {... Transaction ID #[flowVars.tran ....}] ^

Do you have any clue about this problem or how can I fix it?

Thanks in advance.


Solution

  • You need to rearrange the expression so all of it is within the #[....]

    subject="#['Transaction ID ' + flowVars.transactionId]"
    

    Some fields get parsed as MEL expressions and some are more like templated strings that allow expression substitutions.

    (One of Mule's annoyances)