i only get one binary image/data when i use ‘{{ $(‘images’).item.binary.data }}’ and not everything, thus making it impossible to add multiple attachments in gmail. what do i do. there is another node between the http node which gets the image and the gmail node, so there is a need for set node. thank you
Hey @Dharun_Kumar! This is a classic ‘item vs. list’ struggle in n8n.
The reason you’re only getting one image is because your expression is explicitly pointing to a single item’s binary property. When n8n runs this, it evaluates it for the first item and stops.
To send multiple attachments in Gmail, you need to provide an array of objects to the Gmail node’s ‘Attachments’ field.
Here’s the fix:
- After your HTTP node (which I assume is in a loop or returns multiple items), use the Aggregate Binary Files node.
- Set the ‘Action’ to ‘Merge into a single item’.
- This will give you a single item that contains ALL your binary files (e.g., data0, data1, data2…).
- In your Gmail node, under ‘Attachments’, use an expression that maps these out.
If you specifically need to keep them as separate items through a ‘Set’ node first, make sure you aren’t accidentally flattening the data. But honestly, the Aggregate Binary Files node is exactly what was built for this ‘one email, multiple files’ scenario.
Give that a shot and let me know if it clears the hurdle!
Hi @Dharun_Kumar Let me clarify, you need to use the aggregate node with specifically All Item Data and Include Binaries mode enabled , and this should be before the Gmail node so the passed down files aggregate and becomes one single item that would not trigger gmail node more than once, and to refer all those aggregated files you need to use this {{ Object.keys($binary).join(',') }} so that all those aggregated files can be added, in the gmail field.
One additional approach that has worked well for me in similar cases is to merge the binary data using a Code node, so that all files end up in a single item before reaching the Gmail node. In my experience, this gives you full control and ensures Gmail receives one item containing all attachments.
Example:
const binaries = {};
for (const item of $input.all()) {
Object.assign(binaries, item.binary);
}
return [
{
json: {},
binary: binaries,
},
];