Save email attachments to Nextcloud

hello, is it possible to have something like this in node-red?

googling, i found this https://n8n.io/workflows/1344-save-email-attachments-to-nextcloud/ but chatgpt is unable to convert this into node-red json

Welcome to the forums @tty6747fg8

Whilst CPT is handy - It should not be the goto - its not a miracle worker.

However... Don't over think it, nodes exist to do what you want.

  1. Using the Node : node-red-node-email (node) - Node-RED

    • Download the emails.
      • Each email has an attachments array (I believe) @dceejay may be able to confirm?
  2. For each attachment in that array, upload it using a nextcloud node
    - A few nodes exist: Library - Node-RED

The tools are available - use them to engineer your solution

yes email has the attachment part but is on base64


Content-Type: application/pdf; name="xxxx.pdf"
Content-Disposition: attachment; filename="xxxxx.pdf"
Content-Transfer-Encoding: base64

You can convert them to binary from base64 pretty easily

const fileBlob = Buffer.from(msg.attachments[0].data, 'base64'); /* I don't use email, so may have the path wrong */

where do i place that?

We can only provide code examples, we can't possibly know your setup in all the required detail - each flow is different.

But...

Using a function Node
(Between your attachment processing logic, and the next cloud upload routine)

const fileBlob = Buffer.from(msg.attachments[0].data, 'base64');

/* Im just guessing the properties that a random Next cloud node might need */
msg.payload = {
    fileName: 'Some Name',
    fileData: fileBlob
}

return msg /* send to next cloud node */

I think the change node is also capable - @E1cid, has God Mode on that stuff :smile:

We won't create this fully for you - only lend advice / code examples, of how it can be achieved.
If you want this fully developed - consider posting in Jobs - Node-RED Forum

is not a big stuff email node to get gmail -> magic-> nexctclaud

hmm maybe i will throw 5-10€ to this problem even if wont make any money from it

Sorry - I thought it was a bigger project.

If it’s only a couple of nodes needed, and is of a simple manner, I’m sure someone from the community will share a compete flow.

I don’t use email in node red, or use next cloud, so don't have the nodes / exposure needed.

I use some simple setup like this and it works for me

image

I am able to send csv, pdf , txt files like this without any issue.

Wrong way round @smanjunath211 :slightly_smiling_face:

Anyway, this has been going on long enough, so here is a flow to get you going @tty6747fg8
I don't use the nodes you need, so replace and configure them to suite.

Not tested, and you may need to fix some things.
The content is apparently already a buffer

[{"id":"5c016138b11d14c1","type":"tab","label":"Email -> Next Cloud","disabled":false,"info":"","env":[]},{"id":"232f83a77a8855fb","type":"function","z":"5c016138b11d14c1","name":"Place Holder","func":"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":360,"wires":[["f941a88476772542"]]},{"id":"71140f78fba8d659","type":"comment","z":"5c016138b11d14c1","name":"Replace with Email IN","info":"","x":320,"y":320,"wires":[]},{"id":"f941a88476772542","type":"function","z":"5c016138b11d14c1","name":"Prcoess any found attachment(s)","func":"/* Just guessing here */\n\nmsg.attachments.forEach(function (attachment){\n    const msg = {\n        topic : attachment.filename,\n        payload : attachment.content\n    }\n    node.send(msg);\n});","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":360,"wires":[["111c3bd8eacfdd8e"]]},{"id":"111c3bd8eacfdd8e","type":"function","z":"5c016138b11d14c1","name":"Place Holder","func":"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":970,"y":360,"wires":[[]]},{"id":"e19eb2ee744d538e","type":"comment","z":"5c016138b11d14c1","name":"Replace with NextCloud","info":"","x":930,"y":320,"wires":[]}]

1 Like

Yup, realised after posting it.

1 Like

Apparently the nextcloud node needs to a fixed file name and cannot get the whatever file comes from the email, if this is correct then the nextcloud node is useless

Not quite...

You can set the filename (and directory) in a message.

msg.filename
msg.directory

https://flows.nodered.org/flow/bde00d6ce821849daee62c904fd80f59

I don't use NextCloud, so just going off the readme

placing that in the file and directory field dont work

Then I am afraid you will need to look elsewhere (another Node)
or raise it with the author.

Possible Nodes
Next Cloud Search : Library - Node-RED
Web Dav Search : Library - Node-RED

Show us the message that you are feeding to the node.

1 Like

is a gmail with attachment the one i used for testing is over 7k lines long, currently i got it working on n8n

I meant that you should feed the message into a debug node set to Output Complete Message and copy/paste what you see. I am particularly interested in what is in msg.filename and msg.directory.

Do you mean that your problem is solved?

if i do

in the debug i only get the simple email not raw email so in the debug mode only get 33 lines, when the email have 244 lines before attachment, imo the attachment does not even load

setting the debug to complete msg object
returns more data a total of 17 000 characters

while the full email has over half million

not really because i would prefer to have this in a open source platform vs a fremium-open source platform because if i learn how to use it i dont surprises if they change business model

The amount of text shown in the debug panel is limited in settings.js:

/** The maximum length, in characters, of any message sent to the debug sidebar tab */
    debugMaxLength: 1000,

This doesn't mean your email will also be truncated.