# HowTo send Email with local attachment

**URL:** <https://discourse.nodered.org/t/howto-send-email-with-local-attachment/53725>\
**Category:** General\
**Created:** [14 November 2021 15:40 UTC](https://discourse.nodered.org/t/howto-send-email-with-local-attachment/53725 "2021-11-14T15:40:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cavekeeper](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Cavekeeper](https://discourse.nodered.org/u/Cavekeeper)\
**Post date:** [14 November 2021 15:40 UTC](https://discourse.nodered.org/t/howto-send-email-with-local-attachment/53725/1 "2021-11-14T15:40:30Z")

</div>

I have already read carefully in the forum and put together various building blocks. But I don't get an attachment at the end. The text is there, but the photo is missing. I think it's relatively easy and I like to learn. Maybe someone can help me?

 ![Bildschirmfoto 2021-11-14 um 16.31.40](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8b7640e538ea7c052088e6a3ec80f16b12b87d50.png)

```auto
[{"id":"dee99cab99266e8b","type":"file in","z":"49e813ed38cbfdd9","name":"Deepstack Foto Flur","filename":"/config/www/snapshots/deepstack/flur/deepstack_object_diskstation_flur_latest.jpg","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":1960,"y":140,"wires":[["42d4baf4fae75719"]]},{"id":"58911bc8d4043075","type":"inject","z":"49e813ed38cbfdd9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1720,"y":140,"wires":[["dee99cab99266e8b"]]},{"id":"330af8200b4403a3","type":"debug","z":"49e813ed38cbfdd9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2610,"y":140,"wires":[]},{"id":"5e11ea515c3e05bb","type":"function","z":"49e813ed38cbfdd9","name":"write Email","func":"msg = {\n topic: `Kamera Flur @ ${Date()}`,\n payload: \"ACHTUNG - Einbruch Tür Flur \",\n attachments: [{\n \"filename\": \"deepstack_object_diskstation_flur_latest.jpg\",\n \"content\": msg.payload,\n \"encoding\": 'base64'\n }]\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2410,"y":140,"wires":[["330af8200b4403a3"]]},{"id":"42d4baf4fae75719","type":"change","z":"49e813ed38cbfdd9","name":"set attachment","rules":[{"t":"set","p":"attachments","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2200,"y":140,"wires":[["5e11ea515c3e05bb"]]}]

```

Maybe it's even easier than I imagined - with fewer building blocks?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [14 November 2021 17:28 UTC](https://discourse.nodered.org/t/howto-send-email-with-local-attachment/53725/2 "2021-11-14T17:28:20Z")

</div>

> [@Cavekeeper](#):
>
> The text is there, but the photo is missing

Try to change you File read node to Buffer  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e5c0682442c1cc18e756296a4c9f48ccc7c68da.png)

and remove the `base64` encoding from `attachments`

**Example:**

```auto
[{"id":"dee99cab99266e8b","type":"file in","z":"5847b7aa62131d37","name":"Deepstack Foto Flur","filename":"C:\\share\\Test.png","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":380,"y":1300,"wires":[["5e11ea515c3e05bb"]]},{"id":"58911bc8d4043075","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":1300,"wires":[["dee99cab99266e8b"]]},{"id":"330af8200b4403a3","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":1300,"wires":[]},{"id":"5e11ea515c3e05bb","type":"function","z":"5847b7aa62131d37","name":"write Email","func":"let fileBuffer = msg.payload;\n\nmsg = {\n topic: `Kamera Flur @ ${Date()}`,\n payload: \"ACHTUNG - Einbruch Tür Flur \",\n attachments: [{\n \"filename\": \"deepstack_object_diskstation_flur_latest.jpg\",\n \"content\": fileBuffer\n }]\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":1300,"wires":[["330af8200b4403a3"]]}]

```

---

<div class="post-metadata">

**Author:** ![Cavekeeper](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Cavekeeper](https://discourse.nodered.org/u/Cavekeeper)\
**Post date:** [14 November 2021 17:47 UTC](https://discourse.nodered.org/t/howto-send-email-with-local-attachment/53725/3 "2021-11-14T17:47:17Z")

</div>

Many many thanks. It works perfectly.  
I would not have come across the entry with the FileBuffer so quickly. brilliant

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 November 2021 17:47 UTC](https://discourse.nodered.org/t/howto-send-email-with-local-attachment/53725/4 "2021-11-28T17:47:40Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
