Skip to main content

addAttachment()

Last updated 5/03/2026

Definition​

is a function on the
Five
object that allows you to attach a file to an email generated during a a mail merge process.

Examples​

Adding attachments to a mail merge​

This code demonstrates how to automatically include submission attachments in a mail merge. The function must be attached to the Do Merge Record event of the mail merge record in order to execute during the email generation process.

When the mail merge processes each record, the function checks whether any attachments are associated with that submission. If attachment exists, it loops through each file, converts it into a properly formatted Data URI using

, and then adds it to the outgoing email using

five.addAttachment()
.

After all attachments have been processed, the function returns a successful result, allowing the mail merge process to continue and send the email with all relevant files included.

Add attachments to a mail merge
function DoAddSubmissionAttachments(five: Five, context: any, result: FiveError): FiveError {
if (context.Attachments && context.Attachments.length > 0) {

for (let i = 0; i < context.Attachments.length; i++) {
const attachment = context.Attachments[i];
five.addAttachment(five.toDataURL('application/pdf', attachment.file), attachment.name);
}
}

return five.success(result);
}