Mail-Node Attachement unreadable

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/" 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.

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

{"_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

{"_msgid":"d97da717.34b998","topic":"helloWorld Thu  17:34","payload":"helloWorld.txt in Attachement: ``","filename":"/home/pi/","attachments":{"filename":"","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"}}

Pretty sure msg.attachments should be an array.

See the built in help.

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?

UTF8 String or Buffer in FileIn node ?


1 Like

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

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