Camunda Mail Connector using Freemarker template

Hey,
I am using Camunda mail connector and when I start a process I set some variables.
And in the Send Task (Email),I want to add the variable to Mail Body using free marker template.
But the variable value is not getting set.
Any ideas on this?

@Mass_Shake in freemarker template you have to mention the variables as ${variablename} or execution.getVariable("variablename") ,so those variables will be resolved at runtime from the execution context

I am getting this error.

freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> VAR_EXTERNAL_ID [in template “unknown” at line 1, column 6]


This is how I start the process.

I pass the varibales from here.

mail.bpmn (8.7 KB)
This is my BPMN file

@Mass_Shake in the send task you have used the constant, freemarker will not be aware of those constants, use the exact variable name.

image

Lets say you have defined a field like this, public final static String VAR_INCIDENT_ID="incidentId"; then you have to configure incidentId in the template.

The constant is public final static String VAR_INCIDENT_ID=“VAR_INCIDENT_ID” and hence I am using ${VAR_INCIDENT_ID}

@Mass_Shake, noticed that from is missing in your connector config. If you have configured the from attribute in mail.properties file, then not required to set it in connector input parameters.

Check this example in the section mail-send:

Also make sure dependency in classpath:

<!-- freemarker -->
  <dependency>
    <groupId>org.camunda.template-engines</groupId>
    <artifactId>camunda-template-engines-freemarker</artifactId>
  </dependency>

I have referred to the same example.
Also the dependency is there.

Can we pass entire JSON object while starting the process?
And access the json in free marker template

you can use, but fields are need to be accessed like this : ${user.userId} in freemarker template

Similar to that github example i created sample flow which works fine for me, i was able to test it.

sendTaskTest.bpmn (4.7 KB)

image

1 Like

did you configured “from” attribute in either mail-config.properites or input param in connector config of send task?

image

How did you pass the JSON to process engine.?

Yes ,I have configured it in mail.properties

in mail-config.properties, the property should be mail.sender not from

Refer this link: JSON | docs.camunda.org