I currently have a workflow that is taking inbound email via IMAP Email and eventually sending elements of the data to a HTTP Request POST. What I’m hoping to do next is grab any attachments of the email, upload them to either Wasabi S3 (preferably) or FTP, and then grab the URL of the files and append them to the rest of the data from the IMAP Email so I can add it my JSON that is posted. My thinking is that I would go from IMAP Email to a function that splits the binary data.
for (let item in items) {
if(Object.keys(items[item]).includes('binary')){
return Object.keys(items[item].binary).map(key => {
return {
json: {},
binary: {
data: items[item].binary[key],
}
}
});
}
}
return items;
From there, I would use S3 or FTP node to upload the attachments. But, it’s not clear if I can upload multiple attachments via either of those or if I have to iterate through the attachments individually. Then, I would use an Append node so that this:
[
{
"textHtml":"<b>Boo</b>",
"textPlain":"Boo",
"metadata":{
"delivered-to":"[email protected]",
"reply-to":"[email protected]"
},
"from":"Scary Stories <[email protected]>",
"subject":"Spooky Attachments [Casper]",
"date":"Thu, 16 Dec 2021 18:21:18 +0000 (UTC)",
"to":"Email Account <[email protected]>"
}
]
Becomes something like this:
[
{
"textHtml":"<b>Boo</b>",
"textPlain":"Boo",
"metadata":{
"delivered-to":"[email protected]",
"reply-to":"[email protected]"
},
"from":"Scary Stories <[email protected]>",
"subject":"Spooky Attachments [Casper]",
"date":"Thu, 16 Dec 2021 18:21:18 +0000 (UTC)",
"to":"Email Account <[email protected]>"
},
{
"attachments":[
{
"id":1,
"url":"https://wasaby.sys/bucket/filename1.jpg"
},
{
"id":2,
"url":"https://wasaby.sys/bucket/filename1.jpg"
}
]
}
]
Due to how the endpoint expects to get the JSON, I have to construct it a bit differently and send it RAW. I use this function to create that JSON and would also appreciate help getting the attachments into this function.
items[0].json.sample = {
"summary": $node["IMAP Email"].json["subject"],
"details": $node["IMAP Email"].json["textHtml"],
"user_id": $node["SetGenUser"].json["user_id"]
}
return items;
Thank you.