How to dynamically attach an attachment to an email

Hi!

I recently discovered this section of the help page:

If I understand correctly, this would allow me to attach files to the email, but based on the instructions I cannot really wrap my head around what I need to add to the script step.

Could someone give an example?

Hi,

Since fileData contains base64 encoded content, it can be extracted using regex and filled into base64Content.

For example:

doo.workflow.attachment.clearAllDynamicAttachments();

const attachments = doo.model.file?.value || [];

const regex = /base64,(.+)$/;

if (attachments.length) {
  for (const attachment of attachments) {
    const base64Content = attachment.fileData?.match(regex);
    attachment.base64Content = base64Content[1] || '';
    doo.workflow.attachment.addDynamicAttachment(attachment);
  }
}

With Regards,

Filip

1 Like