Hi,
I want to send e mail with attachments and before doing that, I need to gather all the attachments with the gDriveIds of attachments and then send them in one mail.
But I couldn’t achive it like this. I’m able to get the attachment but in every attachment I get, it sends a mail.
How can I collect all the attachments I download from drive and send them in one mail?
Information on your n8n setup
n8n version:Version 0.219.0
Database (default: SQLite):
n8n EXECUTIONS_PROCESS setting (default: own, main):
Running n8n via (Docker):
Operating system:Linux
I found a couple of solutions,
But these are not for files, works well with data.
As @jan said, it will iterate over the result set until it gets an exception and then just break the iteration and return the result.
If you look at the code it becomes a bit easier to see:
const allData = []
let counter = 0;
do {
try {
const items = $items("Increment", 0, counter).map(item => item.json);
allData.push.apply(allData, items);
} catch (error) {
return [{json: {allData}}];
}
counter++;
} while(true);
Hey @ottic !
Were you able to find a solution? If you need more help do let us know
1 Like
Hey @BramKn ,
This one didn’t solve my issue with files. It collects the data correct but not the binary files.
Then I tried this algorithm to collect all files into one but this algorithm cannot see both files, can only see a file from one cycle;
let results = [];
for (const item of $input.all()) {
for (key of Object.keys(item.binary)) {
results.push({
json: {
fileName: item.binary[key].fileName
},
binary: {
data: item.binary[key],
}
});
}
}
return results;
BramKn
April 24, 2023, 7:57am
4
Hi @onurbolaca
try this
const allData = []
let counter = 0;
do {
try {
const items = $items("RSS Feed Read", 0, counter);
allData.push.apply(allData, items);
} catch (error) {
return [{allData}];
}
counter++;
} while(true);
1 Like
Hey @BramKn ,
Thank you for your answer,
I applied what you provide and the data looks like this now;
I need to put them into attachments fields of send mail node;
BramKn
April 24, 2023, 8:19am
7
Hi @onurbolaca
Try this
const allData = []
let counter = 0;
do {
try {
const items = $items("RSS Feed Read", 0, counter);
allData.push.apply(allData, items);
} catch (error) {
return [allData];
}
counter++;
} while(true);
Hey @BramKn ,
Still the same;
Do you know any other way?
Thank you!
This was working well but couldnt combine with what I have;
let results = [];
for (const item of $input.all()) {
for (key of Object.keys(item.binary)) {
results.push({
json: {
fileName: item.binary[key].fileName
},
binary: {
data: item.binary[key],
}
});
}
}
return results;
BramKn
April 24, 2023, 8:25am
9
It is simply the return data being wrong, and me not looking properly
another one
const allData = []
let counter = 0;
do {
try {
const items = $items("RSS Feed Read", 0, counter);
allData.push.apply(allData, items);
} catch (error) {
return allData;
}
counter++;
} while(true);
1 Like
Thanks @BramKn ,
This one merge the files as one result.
I cannot send them in one mail though, it sends two mails for each file;
Do you have any idea about how to send them in one mail?
It comes like this;
Drive Node
Merge Data JS Node
BramKn
April 24, 2023, 8:40am
11
Ah didn’t see you wanted to have em on one item.
You need to add them together idd. I don’t have a quick example for you.
1 Like
Thanks @BramKn ,
Here is how it works;
const result = { binary: {} };
const resultArr = [];
let counter = 0;
do {
try {
const items = $items("Download Files", 0, counter);
// Add each item to the binary object of the result object
items.forEach((item, index) => {
result.binary[`fileName${counter + index}`] = item.binary.data;
});
} catch (error) {
resultArr.push(result);
return resultArr;
}
counter += items.length;
} while (true);
FelixL
April 24, 2023, 9:31am
13
I haven’t tried it yet, but in a never n8n version the “split in batches” node has a “done” output which as far is i understood it, should output all items at once.
You can aggregate these items into one with the List node.
EDIT: I do not know if that works with binary data (files).
@FelixL ,
Please see above. It is possible with js code to combine all files as different arrays and same array like in here: Merge Two Files in First Row for One Mail
system
Closed
May 1, 2023, 9:34am
15
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.