From MSSQL to csv to email

The file is fine - it just needs to be renamed to xxx.csv.

The Email node says...

If the payload is a binary buffer then it will be converted to an attachment. The filename should be set using msg.filename

and

with a subject of msg.topic

so add that to the function node...

msg.topic = "Sensor data attached"
msg.filename = "data.csv"
msg.payload = Buffer.from(msg.payload);
return msg;

Here is a working example I knocked up...

[{"id":"a14fc6ed.f35998","type":"inject","z":"f1d1607b.077aa","name":"Simulated data","topic":"","payload":"[{\"colour\":\"red\",\"value\":\"#f00\"},{\"colour\":\"green\",\"value\":\"#0f0\"},{\"colour\":\"blue\",\"value\":\"#00f\"},{\"colour\":\"cyan\",\"value\":\"#0ff\"},{\"colour\":\"magenta\",\"value\":\"#f0f\"},{\"colour\":\"yellow\",\"value\":\"#ff0\"},{\"colour\":\"black\",\"value\":\"#000\"}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":460,"wires":[["89849c13.01d3e"]]},{"id":"89849c13.01d3e","type":"csv","z":"f1d1607b.077aa","name":"","sep":",","hdrin":false,"hdrout":true,"multi":"one","ret":"\\n","temp":"colour,value","skip":"0","x":290,"y":460,"wires":[["73812b52.25b8d4"]]},{"id":"4c5ed49.07eb82c","type":"e-mail","z":"f1d1607b.077aa","server":"smtp.gmail.com","port":"465","secure":true,"tls":false,"name":"","dname":"","x":730,"y":460,"wires":[]},{"id":"79d99799.5e6318","type":"debug","z":"f1d1607b.077aa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":500,"wires":[]},{"id":"73812b52.25b8d4","type":"function","z":"f1d1607b.077aa","name":"Set filename and convert to buffer","func":"msg.topic = \"Sensor data attached\"\nmsg.filename = \"data.csv\"\nmsg.payload = Buffer.from(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":460,"wires":[["79d99799.5e6318","4c5ed49.07eb82c"]]}]
1 Like