How to send multiple attachments in a single email using Email V2

If you require to send multiple file attachments in a single email, please follow the instructions below:

Illustrated in the image below is an example of a flow that queries three error logging buffers, generates an Excel file for each, and sends all three attachments in one email using the Email V2 step.

Begin the flow, Add a Start Flow and the Pass-Through will be automatically added. Then add a series control step, Create a branch for each file that will be sent.

image

Each of the Series control step branches will contain the same set of steps. Query the buffer, Format the Error message, Combine records, Write to an Excel file, convert the file to Base64, and return the output.

Add a Buffer Query as the source step that will return the data from the buffer
Note: If you are returning a list of fields, Add a field to each field name to ensure that there is no conflict when querying the buffer due to a run’s default field names.

For Example:

SELECT record as rec FROM tableName

image

Format Error, Add a calculator step to format fields added to the spreadsheet and remove default system fields.

The data can be written to the spreadsheet, Add a Combine step to combine the records and an Excel Writer step to add records to the spreadsheet.

image

The Email V2 step requires the file to be a base64 string, Add a Byte group step after the Excel Writer step that will take in the file as binary and output as Base64 to a field called “base64FileString”.

image

Then Add a Calculator step at the end to return the base64 string.

At the end of each series control step branch, configure the Return by click on the arrow box. Set the type to String and add it to the record in the source then provide an object name to return the data too.

image

After creating all series control step branches for each file that will be created. Add a calculator to set up the attachments for the Email V2 destination.

Create an array called attachments, For each series control branch add the code provided below which will check if there is data from the Return of our Series control step branch and push the filename, content type, and content to the attachments array. Thereafter add the attachments array to the record and set the return.

Code for each series control branch file:

if (inputRecord.Sub1_Errors !== "[]") {
    attachments.push({
        filename: "Errors_Series_1.xlsx",
        type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        content: inputRecord.Sub1_Errors
    });    
}

In the Email v2 destination. Add a To email address, these addresses can be added to a solution parameter and referenced in the To Address.
Add a meaningful Subject value
For the Attachments, Click on the paper clip icon next to the field name and specify @record.attachments
Add a meaningful message to the body.

The email will be sent when executed and each file will be attached.