🤖 How to send email with attachments

:robot: Make Bot here bringing solutions to some of your FAQs :robot:


:question:

Hello there! I’m trying to send an email with attachments using a webhook. The problem is that I don’t know how to make my scenario capable of processing N number of attachments depending on how many arrive through the webhook.



:reply:

In order to provide a more specific answer, a bit more context would be needed. However, here are a few hints that may point you in the right direction :arrow_down:

Let’s assume that you have a scenario that starts with a webhook and ends with an Email module.

Further, let’s assume that you are sending your attachments in the data payload through the webhook. The data may have a form of a JSON, for example as follows:

{

"attachments": [

{

"name": "file1.png",

"data": "binarydata1"

},

{

"name": "file2.png",

"data": "binarydata2"

}

]

}

The Email module expects the attachments as an array of collections, where each collection has two mandatory parameters: “data” and “fileName”. Let’s construct a scenario that will produce this:

  1. In the webhook module, make sure that you select “No” in the “JSON pass-through option”. You may need to toggle the “Show advanced settings” switch to see this option. You don’t need to define any data structure for validation.


  1. Next, connect an Iterator module after the webhook and select the array that you want to iterate. In case of the data structure mentioned above, this would be “attachments[ ]”. Make sure that the “Map” toggle is turned on.

Important note: In order to map the data from the webhook, you need to run the hook once and therefore load it with data.


  1. Next, connect an Array aggregator module right after the Iterator. We will configure it later.

  2. Attach the Email module after the Array aggregator.


  1. Now, let’s go back to the Array aggregator. Click on the module in the scenario to display its properties and:
  • Select the Iterator as the Source Module.
  • Select “Email - Send an Email: Attachments” as the Target structure type. This option will be automatically available because you already have an Email module connected in your scenario.
  • Now let’s map the data: Click into the “File name” text box and select the “name” parameter of the Flow Control - Iterator module as the value. Next, click into the “Data” text box and select the “data” parameter of the Flow Control - Iterator module as the value.
  • We’re done, click OK.


  1. Finally, we need to map the newly created array of attachments in the Email module:
  • Click on the Email module in the scenario editor to display its properties.
  • Find the “Attachments” section and turn on the “Map” toggle.
  • Click into the empty text box right underneath it and select the “Array[ ]” parameter of the Flow Control - array aggregator module as its value.
  • Click OK to store the module settings.


When you run the scenario now and send the payload to your webhook, the attachments will be added to the email :nerd_face:

Helpful LInks
:make: Email integration page