Can't add email attachment dynamically using Camunda Send-Email Connector

I am using the email-send Connector of Camunda.

I am trying to add attachments dynamically to an auto-generated email. As explained here, the connector requires to specify the values of the variable "fileNames" that references the attachment location at the modeling stage. The value of the variable itself can be changed dynamically at the process execution stage. However, in my case, I would like to dynamically add or retrieve values from the list variable

"fileNames".

The screenshot below shows the static entries that I am using currently to fill the list "fileNames".

My question is : is there a way to specify dynamically (from java code) the values of the

"fileNames" list ? Thanks in advance for your help :slight_smile:

Hi @Hel,

you could use a process variable which includes all file names you want to attach. You can change the variable in your process and reference it in the connector as fileNames.

Does this help you?

Best regards,
Philipp

1 Like

Hi @Philipp_Ossler,

Thank you for your reply. I appreciate it :blush:

Here is what I tried:

  • Step 1: Create a process variable in a Delegate Class whish is called before the sendEmail Action.
    In this variable, I put all my file names that I want to attach to my email.
    The variable I created has the same name as the connector input parameter fileNames: execution.setVariable("fileNames", fileNamesPath);

  • Step 2: I kept the declaration of ā€œfileNamesā€ input parameter in the process model (as shown in the screenshot below). However, this time, I havenā€™t specified any item value for the list fileNames. I was hoping, in somehow, the process will pick the values from the process variable names that I created in step 1 but it does not :frowning:

I donā€™t see how can I reference explicitly the process variable that I created (step 1), in the ā€œfileNamesā€ input parameter of the Connector.
Is there a mean to set the connector input parameter to the process variable I defined earlier ? something like Connector.fileNames=${myfileNamesVariable}?

Looking forward your help.

Best Regards,
Hanane

Hi @Hel,

try to set the input parameter filesNames to type Text and value ${fileNamesPath}. This should use the process variable which is defined in the previous task.

Does this help you?

Best regards,
Philipp

Hi @Philipp_Ossler,

Your tip works like a charm!

I couldnā€™t imagine that setting the connector parameter fileNames as ā€˜ā€˜Textā€™ā€™, which is not complaint to the type that is specified in the connector documentation (List), would never work!

I was expecting a big error caused by an illegal cast of text as a list but fortunately, there was no error :blush:

The engine adapted the type of the text parameter I declared using the type of the referenced process variable: amazingly smart :wink:

Thank you very much for your help!

Best regards,
Hanane

Yeah, in the Camunda Modeler it is not obvious that you can use an expression :sweat_smile: You can find a note in the Camunda docs: https://docs.camunda.org/manual/7.10/reference/bpmn20/custom-extensions/extension-elements/#inputparameter

1 Like

Hello,
Iā€™m beginner to Camunda, I used a connector too and I need to send mail data (like the recipient, subject messageā€¦ ) dynamically. Regarding the conversation and documentation,
I used a delegate class where i set the variable execution.setVariable(ā€œvarNameā€, varValue)
set the input parameter assignement value in panel properities to ${varName} or ${varValue}
camunda:connector
camunda:inputOutput
<camunda:inputParameter name=ā€œmessageā€>Message</camunda:inputParameter>
<camunda:inputParameter name=ā€œsubjectā€>Subject</camunda:inputParameter>
<camunda:inputParameter name=ā€œtoā€>${varName}</camunda:inputParameter>
</camunda:inputOutput>
camunda:connectorIdmail-send</camunda:connectorId>
</camunda:connector>
But it gives this error Unknown property used in expression: ${varName}, I know that I miss something
Any help, thank you

@HEss can you upload your bpmn model? And also specify in which Activity/Delegate the variable was been set?

Thank you for your reply @aravindhrs,
You can find attached the bpmn model. So here is the thing, I used a JavaDelegate to set this variable, but because my task implement a connector, it seems like there is no contact to understand the variable thatā€™s why they give this error ā€œUnknown property used in expression: ${varName}ā€, and for me I want to let the connector to send emails.
connector-ex.bpmn (3.8 KB)
Thank you

Attached bpmn doesnā€™t have listener configuration to the any of the activities.

1 Like

Hello @aravindhrs,
I knew that Iā€™ve missed something, It was exactly the listener config. I forget adding the listener and point it to my JavaDelegate.
Thank you very much @aravindhrs