# Mail-Node Attachement unreadable

**URL:** https://discourse.nodered.org/t/mail-node-attachement-unreadable/43873
**Category:** General
**Created:** [8 April 2021 16:03 UTC](https://discourse.nodered.org/t/mail-node-attachement-unreadable/43873 "2021-04-08T16:03:22Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jsail](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jsail/32/20176_2.png) [@jsail](https://discourse.nodered.org/u/jsail)
#### Post date: [8 April 2021 16:03 UTC](https://discourse.nodered.org/t/mail-node-attachement-unreadable/43873/1 "2021-04-08T16:03:22Z")

</div>

I am stock with the node attachements.  
first I used the file-node to "/home/pi/helloWorld.txt" and send it to the mail-node. The Mail arrives and the attachement is ok.  
When I send "/home/pi/helloWorld.zip" attached, the Mail arrives also but the attachement can not be opend.  
As my goal would be to send a smal sqligt.db File for backup.

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

Function Node:  
file = msg.filename; // create local file variable for convenient reference  
var d = new Date(); // create current date object for the time string  
var tstring = d.toString().substring(0,4) + d.toString().substring(15,21);

msg.attachments =  
{ filename : file.substring(file.lastIndexOf('/')+1,file.length),  
content : msg.payload }; // content should be a file binary buffer

msg.topic = "helloWorld " + tstring; // email subject  
msg.payload = "helloWorld.txt in Attachement: `" + msg.attachments.filename + "`"; // email body  
return msg;

txt-Attachement works

```auto
{"_msgid":"9455be24.e895c","topic":"helloWorld Thu 17:30","payload":"helloWorld.txt in Attachement: `helloWorld.txt`","filename":"/home/pi/helloWorld.txt","attachments":{"filename":"helloWorld.txt","content":"hello world"}}

```

Binary-Attachement does not work

```auto
{"_msgid":"d97da717.34b998","topic":"helloWorld Thu 17:34","payload":"helloWorld.txt in Attachement: `helloWorld.zip`","filename":"/home/pi/helloWorld.zip","attachments":{"filename":"helloWorld.zip","content":"PK\u0003\u0004\n\u0000\u0000\u0000\u0000\u0000���R�\u0011J\r\u000b\u0000\u0000\u0000\u000b\u0000\u0000\u0000\u000e\u0000\u001c\u0000helloWorld.txtUT\t\u0000\u0003\u0003!o`\u0003!o`ux\u000b\u0000\u0001\u0004�\u0003\u0000\u0000\u0004�\u0003\u0000\u0000hello worldPK\u0001\u0002\u001e\u0003\n\u0000\u0000\u0000\u0000\u0000���R�\u0011J\r\u000b\u0000\u0000\u0000\u000b\u0000\u0000\u0000\u000e\u0000\u0018\u0000\u0000\u0000\u0000\u0000\u0001\u0000\u0000\u0000��\u0000\u0000\u0000\u0000helloWorld.txtUT\u0005\u0000\u0003\u0003!o`ux\u000b\u0000\u0001\u0004�\u0003\u0000\u0000\u0004�\u0003\u0000\u0000PK\u0005\u0006\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000T\u0000\u0000\u0000S\u0000\u0000\u0000\u0000\u0000"}}

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [8 April 2021 16:10 UTC](https://discourse.nodered.org/t/mail-node-attachement-unreadable/43873/2 "2021-04-08T16:10:13Z")

</div>

Pretty sure msg.attachments should be an array.

See the built in help.

---

<div class="post-metadata">

### Author: ![jsail](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jsail/32/20176_2.png) [@jsail](https://discourse.nodered.org/u/jsail)
#### Post date: [9 April 2021 12:03 UTC](https://discourse.nodered.org/t/mail-node-attachement-unreadable/43873/3 "2021-04-09T12:03:05Z")

</div>

Hi Steve,

I have seen the array in the help.  
But the fact is, that the mail works well, as long I am sending an email with a TEXT attachment. When I attach a BINARY file like ZIP or PNG the attachement arrives defekt.  
I was also able to successfully transmit a TEXT file with a ZIP extension.

Is there a possibility or need to declare the file in a kind of MIME type?

---

<div class="post-metadata">

### Author: ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)
#### Post date: [9 April 2021 13:06 UTC](https://discourse.nodered.org/t/mail-node-attachement-unreadable/43873/4 "2021-04-09T13:06:32Z")

</div>

`UTF8 String` or `Buffer` in `FileIn` node ?

![File](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e701a2b4de3ae54a41683defca53aa9bc1e8e9d6.png)

---

<div class="post-metadata">

### Author: ![jsail](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jsail/32/20176_2.png) [@jsail](https://discourse.nodered.org/u/jsail)
#### Post date: [9 April 2021 14:17 UTC](https://discourse.nodered.org/t/mail-node-attachement-unreadable/43873/5 "2021-04-09T14:17:56Z")

</div>

Thank you for your perfect help.  
I am very happy that I was able to fix my mistake!

---

<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: [23 April 2021 14:18 UTC](https://discourse.nodered.org/t/mail-node-attachement-unreadable/43873/6 "2021-04-23T14:18:15Z")

</div>

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