Dynamically attach multiple files in “Send Email” node – not working - Desperate need of help!

Hi everyone :waving_hand:

I’m trying to build a workflow that sends an email with a dynamic number of file attachments (1 to 3).

After processing, I use a Merge node (mode: Combine by Position) to bring the files into a single item. In the Binary tab of that item, I typically have:

  • data (CSV)
  • File1 (PDF)
  • File2 (PNG)

The goal is to send a single email, containing only the attachments that are actually present (sometimes 1 file, sometimes 2 or 3).

Here the Workflow:

What is the error message (if any)?

The item has no binary field '[object Object]'

This happens when I try to pass the list of binary fields dynamically (e.g. from a Code node).
In the Outlook node, I faced the same issue – I could only get it to work by manually typing the binary field name (like File1). Dynamic field names failed there as well.

I also tried to use Code like this

After that, I used the code in the send Email node: In the “Send Email” node I then tried:

{{ $json.attachments }}

How can I dynamically attach all binary fields from a single item – without hardcoding the field names – and send them all in one email?

Any help or working example would be greatly appreciated :folded_hands:
Thanks!
Luca

Hi,

Can you please share you workflow in a dynamic way, so it can be tested more easily. ctrl-c / ctrl-v in a code segment.

reg,
J.

1 Like

You are on the right track.
Note that there are two modes the Code node operates in.

  • Run once for all items (your current mode) - in this mode you access all items in the input by $input.all() that returns an array of objects, where json and (optionally) binary properties are defined.
  • Run once per each item, under which you can refer current item props using $json and $binary references.

items is not defined giving you a hint.

Check these docs for more details:

Here is a stripped down version of the code:

Hey there!

Thanks for the clarification – that helped me understand the Code node modes better!

I used “Run Once for All Items” and accessed the input with $input.all()[0]. Then I passed the binary data through unchanged:

const item = $input.all()[0]; // dein einziges Item
const binary = item.binary;

return [{
  json: {
    attachments: Object.keys(binary).map(key => ({
      binaryPropertyName: key
    }))
  },
  binary
}];

In the Send Email node, I used this in the Attachments field:


{{ Object.keys($binary).map(key => ({ binaryPropertyName: key })) }}

That worked for dynamically attaching 1–3 files. However, I now got the new issue, that the Send Email Node, does not seem to send Image files. When the Test Email is downloading, I can still see the image file, however when downloaded, it disappears. That happened on Gmail and Outlook.

Also, The Outlook node, however, doesn’t seem to support this approach. It doesn’t accept arrays or comma-separated strings – attachments must be added manually via “Add Option”, or am I wrong?

The attachments field expects a scalar value. With a hope that comma-separated list would work try {{ Object.keys($binary).join(",") }}

If this resolves your question, please mark this post as a :white_check_mark: Solution.

The equivalent expression is $input.first().

What if you have more than one email to send? (assuming that the WF could be triggered by many incoming emails or sorts)
This way you simply strip other items in the queue.

Hey Olek,

your explanation definitely helped – thanks for that!

I have somewhat of a predicament.

The Send Email node works partially – it accepts dynamic attachments via expressions, but for some reason, image files like PNGs disappear after the email fully loads.

The Outlook node sends all file types reliably, including images, plus the formatting of the Email seems a lot easier, – but I couldn’t get it to handle a dynamic number of attachments. It only works when I manually add each file.

Either I figure out a way for the Send Email Node to accept all types of file, or I figure out how to dynamically attach Files to the Outlook Node

Any Ideas? Greatly appreciate your help!

Does this look helpful?

Thanks again for your help!

Turns out the issue is with Outlook – the attachments (especially images) are generated correctly and show up in Gmail, but Outlook filters them out unless they’re embedded in the email body. I even tried a dummy <img src="cid:..."> with display: none to trick Outlook into keeping the image – but that didn’t work either.

I really need the files to show up as standard attachments, not inline images, because our internal system processes them further.

So now I’m back to the original challenge:
Do you have any idea how to dynamically attach a variable number of binary files using the Outlook node?

Sorry and thank you so much for the support. Honestly, I very much appreciate it! That would solve it for good.

I think you need to solve the problem of outlook treating images as inline attachments. And this problem is very likely beyond n8n.

If you forward the email from outlook to Gmail are images still attached? If they are then perhaps it is just outlook being a smart arse. Maybe your system further down the pipeline also can do this. Otherwise there is no much sense in solving multiple attachments issue.

Unfortunately, I won’t be able to help you with Outlook. I do not have an account to test any approaches before suggesting a solution.

Thanks for your reply – and no worries, I appreciate your help so far!

I tested what you suggested:

When I open the same email in Gmail, all attachments (including images) are visible.

But when I open it in Outlook, the image attachments don’t appear – and even when I forward the email from Outlook to Gmail, the images are still missing.

I was thinking to maybe convert any images into pdf.

But for some reason, Outlook only allows for 2 attatchments (all pdf) to go through, when using the Send Email Node.

So it’s clearly Outlook filtering or stripping them out, and unfortunately, our downstream system relies on those files being present as standard attachments.

I totally get that this is likely beyond n8n’s scope – but thanks again for pointing me in the right direction. If I ever find a workaround for dynamic attachments in the Outlook node, I’ll post it here!

2 Likes

Would you by any chance of an Idea?

Well i think @Olek did a good job and i have little to add.

just my 5 cents as i havent played with it. Did you guys see there is a seperate “add attachment action” for outlook? (independent of the send message / attachment field")

from what i could find online “the problem/difference” would be is the content-disposition setting. as with both methods it cannot be set, you need to try to add the attachments in the correct way for (hopefully) set this setting automagically. what you are currently trying to do might be the “hacky” way.

anyway i think that would be something interesting to explore.

reg,
J.

2 Likes

Hey thanks for the input.
I did try appending it to the Draft Node but I also hit the same limitation.

It seems that the Microsoft node just doesn’t accept it. It was surprisingly easy to implement in make.com.

Thanks again for the help.

I encountered this issue as well. I decided to stop fighting it and instead count the number of binaries coming into my email node. Then, I route the workflow with a switch node to an Outlook send email node specifically set up for that number of attachments.

I’m limiting it to a maximum of five attachments based on my logic, with a fallback to notify me if a larger number ever enters the workflow.