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).
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.
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.
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?
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.
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
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!
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.
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.