Attach file (in process variable) to mail sent by connector


I’d like to attach a file to an e-mail send with the bpmn-mail-connector. The file is stored in a process variable. Is there a chance to directly attach that file to the e-mail? I have only found a way to attach a file by passing the file path. When I directly pass the process variable containing the file to the property “fileNames”, the following error occurs: “Cannot cast from File to String”.

Internally the SendMailConnector uses the method attachFile from MimeBodyPart. Theoretically, that method allows to pass a parameter of type File.

The file is generated in the process. There is no need to store the file on the server. So it would be great if the file could be sent by e-mail without storing the file in the file system.

If I have to store the file… Is there a way to store the file only temporarily and delete the file after sending the e-mail?

Thanks for any hint!

Best regards,

Hi Kerstin,

currently, it’s not possible to use a file process variable as attachment. I think it would be a cool feature, so I created a new issue for that. Do you want to provide a feature request?

However, you can also create a temporary file on the server, for example via Java Api Files.createTempFile(...), and write the content of the variable in it. At the end, you can delete the file via Files.delete(...).

Best regards,

If you implement this feature, consider the various ways that attachments may be included (simple text versus binary (base64 encoded)) and what support might be required.

Hello @kerstinguenther

Have you succeeded in saving the file variables as temp files? If so, would you mind sharing some of your code snippets?