# Save email attachments to Nextcloud

**URL:** <https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090>\
**Category:** General\
**Created:** [21 December 2024 15:59 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090 "2024-12-21T15:59:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tty6747fg8](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tty6747fg8](https://discourse.nodered.org/u/tty6747fg8)\
**Post date:** [21 December 2024 15:59 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/1 "2024-12-21T15:59:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 December 2024 16:10 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/2 "2024-12-21T16:10:33Z")

</div>

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](https://flows.nodered.org/node/node-red-node-email)

2. For each attachment in that array, upload it using a `nextcloud` node  
- A few nodes exist: [Library - Node-RED](https://flows.nodered.org/search?term=nextcloud)

The tools are available - use them to engineer your solution

---

<div class="post-metadata">

**Author:** ![tty6747fg8](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tty6747fg8](https://discourse.nodered.org/u/tty6747fg8)\
**Post date:** [21 December 2024 16:12 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/3 "2024-12-21T16:12:53Z")

</div>

yes email has the attachment part but is on base64

```auto

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

```

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 December 2024 16:15 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/4 "2024-12-21T16:15:09Z")

</div>

> [@tty6747fg8](#):
>
> yes email has the attachment part but is on base64

You can convert them to binary from base64 pretty easily

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

```

---

<div class="post-metadata">

**Author:** ![tty6747fg8](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tty6747fg8](https://discourse.nodered.org/u/tty6747fg8)\
**Post date:** [21 December 2024 16:42 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/5 "2024-12-21T16:42:19Z")

</div>

where do i place that?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 December 2024 16:54 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/6 "2024-12-21T16:54:34Z")

</div>

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)

```auto
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 😄

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](https://discourse.nodered.org/c/jobs/21)

---

<div class="post-metadata">

**Author:** ![tty6747fg8](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tty6747fg8](https://discourse.nodered.org/u/tty6747fg8)\
**Post date:** [22 December 2024 01:13 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/7 "2024-12-22T01:13:00Z")

</div>

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

> [@marcus-j-davies](#):
>
> If you want this fully developed - consider posting in [Jobs - Node-RED Forum](https://discourse.nodered.org/c/jobs/21)

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [22 December 2024 03:02 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/8 "2024-12-22T03:02:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [22 December 2024 06:17 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/9 "2024-12-22T06:17:35Z")

</div>

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/eb1655e33024b36d0687ce128ecda97759f0fc30.png)

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [22 December 2024 08:02 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/10 "2024-12-22T08:02:31Z")

</div>

Wrong way round @smanjunath211🙂

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`

> **[Mailparser :: Nodemailer](https://nodemailer.com/extras/mailparser/#attachment-object)**
>
> Nodemailer is a module for Node.js to send emails

```auto
[{"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":[]}]

```

 ![Screenshot 2024-12-22 at 08.02.21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/411bf22988381291899c0352b419b40c74c34528.png)

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [22 December 2024 08:34 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/11 "2024-12-22T08:34:07Z")

</div>

> [@marcus-j-davies](#):
>
> Wrong way round

Yup, realised after posting it.

---

<div class="post-metadata">

**Author:** ![tty6747fg8](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tty6747fg8](https://discourse.nodered.org/u/tty6747fg8)\
**Post date:** [22 December 2024 19:45 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/12 "2024-12-22T19:45:56Z")

</div>

[Apparently the nextcloud node](https://flows.nodered.org/flow/bde00d6ce821849daee62c904fd80f59) 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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [22 December 2024 19:51 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/13 "2024-12-22T19:51:56Z")

</div>

Not quite...

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

```auto
msg.filename
msg.directory

```

 ![Screenshot 2024-12-22 at 19.51.37](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a363bd7b1920d2fcb8f5864346cb5fab8b18168.png)

[https://flows.nodered.org/flow/bde00d6ce821849daee62c904fd80f59](https://flows.nodered.org/flow/bde00d6ce821849daee62c904fd80f59)

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

---

<div class="post-metadata">

**Author:** ![tty6747fg8](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tty6747fg8](https://discourse.nodered.org/u/tty6747fg8)\
**Post date:** [22 December 2024 20:15 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/14 "2024-12-22T20:15:14Z")

</div>

> [@marcus-j-davies](#):
>
> ```auto
> msg.filename
> msg.directory
> 
> ```

placing that in the file and directory field dont work

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [22 December 2024 20:17 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/15 "2024-12-22T20:17:44Z")

</div>

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](https://flows.nodered.org/search?term=nextcloud)  
Web Dav Search : [Library - Node-RED](https://flows.nodered.org/search?term=webdav)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 December 2024 21:38 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/16 "2024-12-22T21:38:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tty6747fg8](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tty6747fg8](https://discourse.nodered.org/u/tty6747fg8)\
**Post date:** [24 December 2024 09:33 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/17 "2024-12-24T09:33:34Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/265cfe520dba5d3e767decc7e541d86e44f8f99a.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 December 2024 10:17 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/18 "2024-12-24T10:17:52Z")

</div>

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.

> [@tty6747fg8](#):
>
> currently i got it working on n8n

Do you mean that your problem is solved?

---

<div class="post-metadata">

**Author:** ![tty6747fg8](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tty6747fg8](https://discourse.nodered.org/u/tty6747fg8)\
**Post date:** [24 December 2024 13:01 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/19 "2024-12-24T13:01:13Z")

</div>

if i do

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/1/a1a6e21f96c2a50c6d603e37393044a7d962e96e.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/019719a1717558f542f34276f120c6970b57430c.png)

while the full email has over half million

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a828bbdc70fb5c498f6dc9dacd991150522c467.png)

> [@Colin](#):
>
> Do you mean that your problem is solved?

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 December 2024 13:09 UTC](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090/20 "2024-12-24T13:09:21Z")

</div>

> [@tty6747fg8](#):
>
> in the debug i only get the simple email not raw email so in the debug mode only get 33 lines

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

```auto
/** 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.

[Next page](https://discourse.nodered.org/t/save-email-attachments-to-nextcloud/94090.md?page=2)
