How to send attachments using Mailgun node?

I would like to send an email using Mailgun and include attachment/s from Airtable.

I’m getting the attachments array from an Airtable node using the List operation.

In the Mailgun node, the attachments field asks for “Name of the binary properties which contain
data which should be added to email as attachment. Multiple ones can be comma separated.”

I’m not sure how to convert the Airtable attachments array into a binary property for mailgun.

Hey @richardjlo!

Welcome to the n8n community! :slightly_smiling_face:

You can use the HTTP Request node to fetch the file. Set the URL parameter to the URL of your file. Use the Editor Expression for doing that. Also, in your HTTP Request node, select ‘File’ in the Response Format field. This way you can get the binary data, and you can send it with the Mailgun node.

Below is an example workflow that fetches a file using the HTTP Request data

Hope this helps! :slightly_smiling_face:

Thanks @harshil1712! Still having some trouble.

Can you take a look at this loom? Loom | Free Screen & Video Recording Software

Thanks!

@richardjlo just tested it, and it is working fine for me.

I had a quick look at your workflow, and it seems to me that the split batches node is not needed. The HTTP node will automatically iterate over all items returned by the Airtable node.

Check the workflows below.

The first one is getting data from Airtable, then downloading one attachment, and then sending the email with Mailgun.

The second one is doing the same, but this time it’s downloading both attachments and sending them with Mailgun.

The Airtable table that I used looks as shown below.

Also, keep in mind that I used the Mailgun sandbox.

I hope this helps. If not, let me know.

Workflow 1
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "={{$node[\"Airtable\"].json[\"fields\"][\"Photo1\"][0][\"url\"]}}",
        "responseFormat": "file",
        "dataPropertyName": "data1",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        860,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "[email protected]",
        "text": "asasasasasasasas",
        "attachments": "data1"
      },
      "name": "Mailgun",
      "type": "n8n-nodes-base.mailgun",
      "typeVersion": 1,
      "position": [
        1200,
        300
      ],
      "credentials": {
        "mailgunApi": "asasasas"
      }
    },
    {
      "parameters": {
        "operation": "list",
        "application": "appXK4YYl2hKGCNCJ",
        "table": "T1",
        "additionalOptions": {}
      },
      "name": "Airtable",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 1,
      "position": [
        490,
        300
      ],
      "credentials": {
        "airtableApi": "asasasa"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Mailgun",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Workflow 2
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "={{$node[\"Airtable\"].json[\"fields\"][\"Photo1\"][0][\"url\"]}}",
        "responseFormat": "file",
        "dataPropertyName": "data1",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        900,
        190
      ]
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "[email protected]",
        "text": "asasasasasasasas",
        "attachments": "data1,data2"
      },
      "name": "Mailgun",
      "type": "n8n-nodes-base.mailgun",
      "typeVersion": 1,
      "position": [
        1490,
        310
      ],
      "credentials": {
        "mailgunApi": "asasasas"
      }
    },
    {
      "parameters": {
        "operation": "list",
        "application": "appXK4YYl2hKGCNCJ",
        "table": "T1",
        "additionalOptions": {}
      },
      "name": "Airtable",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 1,
      "position": [
        490,
        300
      ],
      "credentials": {
        "airtableApi": "asasasa"
      }
    },
    {
      "parameters": {
        "url": "={{$node[\"Airtable\"].json[\"fields\"][\"Photo2\"][0][\"url\"]}}",
        "responseFormat": "file",
        "dataPropertyName": "data2",
        "options": {}
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        890,
        450
      ]
    },
    {
      "parameters": {
        "mode": "mergeByIndex"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1190,
        310
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Mailgun",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
3 Likes

@RicardoE105 thanks! Got it to work!

Good idea of separating the attachments into separate fields. Was initially thinking that I could upload multiple attachments to one field in Airtable, but I think limiting one attachment per field makes more sense.

Glad that it worked. I had no idea that you could have multiple attachments in one field in Airtable. The second workflow should work with it. Just rename the field to attachments on Airtable and in the HTTP node reference attachments[0] and attachments[1].

It would be handy to have the node automatically download all attachments so the HTTP request nodes would not be necessary. I will add it to my todo list.

2 Likes

@richardjlo now the list operation can download attachments automatically. We will let you know when is released.

1 Like

Got released with [email protected]

2 Likes

@RicardoE105 can you tell me how I can use this node? Not sure what I need to modify to get it working. Also, if I have multiple attachments in a cell, do I have to use a Split in batches node to get all the attachments?

Here’s my current workflow with the HTTP request.