Email with 3 attachments?

Hi, I have a flow that triggers from a PIR sensor then 3 cameras take a picture, then email it to me. This is working, however it sends 3 emails with 1 attachment each. I'd like it to be a single email with 3 attachments. Not sure how to go about this, any direction?

Just before Email Node :

msg.payload = "Body Message Text";

msg.topic = "Topic Text";

msg.attachments = [{filename: "File1.jpg", content: msg.File1},
                   {filename: "File2.jpg", content: msg.File2}, 
                   {filename: "File3.jpg", content: msg.File3}];
1 Like

Thanks, did not have success with that just before the email node, I think its because I am triggering 3 simultaneous actions, and then nothing in place to merge that back into one. I actually couldn't even get your suggestion to load the files, and even with that it would still trigger 3 emails. I'll post this part of code so you can see how i'm loading those files.

[{"id":"8cba898c.f9dff8","type":"tab","label":"DrivewayMotion","disabled":false,"info":""},{"id":"66344843.4cef48","type":"mqtt in","z":"8cba898c.f9dff8","name":"DrivewayMotionDetected","topic":"driveway/pir/1/status","qos":"2","datatype":"auto","broker":"e5102fc8.e43f8","x":130,"y":260,"wires":[["14fa6b05.119f65","c693ecd8.cc12d","46d46b6d.53c8a4","b47a5cf4.d4845","e8288616.f6ad38","14f18072.9dc93","c5100061.b951"]]},{"id":"b47a5cf4.d4845","type":"function","z":"8cba898c.f9dff8","name":"motionTimestamp","func":"// below is original\n//msg.payload = msg.payload + \" - \" + new Date().toString();\n// below just prints the last 'no motion' triggers as i'm dumb\nmsg.payload = new Date().toString();\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":80,"wires":[["a691ac66.4c9fa"]]},{"id":"9edace0c.4737c","type":"ui_text","z":"8cba898c.f9dff8","group":"cf1196c4.088ee8","order":3,"width":0,"height":0,"name":"","label":"Last Motion time","format":"{{msg.payload}}","layout":"row-spread","x":890,"y":80,"wires":[]},{"id":"d1b23422.58f0b8","type":"ui_text","z":"8cba898c.f9dff8","group":"cf1196c4.088ee8","order":2,"width":0,"height":0,"name":"Motion status","label":"Motion:","format":"{{msg.payload}}","layout":"row-spread","x":600,"y":160,"wires":[]},{"id":"14fa6b05.119f65","type":"change","z":"8cba898c.f9dff8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"no-motion","fromt":"str","to":"absent","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"motion","fromt":"str","to":"active","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":160,"wires":[["d1b23422.58f0b8"]]},{"id":"5ad3f.443522c1c","type":"mqtt in","z":"8cba898c.f9dff8","name":"drivewaysensor/availability","topic":"drivewaysensor/availability","qos":"2","datatype":"auto","broker":"e5102fc8.e43f8","x":150,"y":420,"wires":[["5c37b51e.3a3bdc","292d78a.3e51688","46d46b6d.53c8a4","daf59c63.307bd"]]},{"id":"5c37b51e.3a3bdc","type":"debug","z":"8cba898c.f9dff8","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":250,"y":580,"wires":[]},{"id":"292d78a.3e51688","type":"ui_text","z":"8cba898c.f9dff8","group":"cf1196c4.088ee8","order":1,"width":0,"height":0,"name":"Controller status","label":"Status","format":"{{msg.payload}}","layout":"row-spread","x":280,"y":620,"wires":[]},{"id":"c693ecd8.cc12d","type":"blynk-ws-out-write","z":"8cba898c.f9dff8","name":"Blynk status","pin":"40","pinmode":0,"client":"fcb61c07.82a5f","x":430,"y":260,"wires":[]},{"id":"c4fa81d.f85658","type":"blynk-ws-out-notify","z":"8cba898c.f9dff8","name":"Blynk app notify","client":"fcb61c07.82a5f","queue":false,"rate":5,"x":600,"y":220,"wires":[]},{"id":"46d46b6d.53c8a4","type":"change","z":"8cba898c.f9dff8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"online","fromt":"str","to":"Driveway controller online","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"motion","fromt":"str","to":"Driveway activity!","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"no-motion","fromt":"str","to":"Driveway quiet","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"offline","fromt":"str","to":"Drivewway controller offline","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":220,"wires":[["c4fa81d.f85658"]]},{"id":"145c6a66.fbbfe6","type":"blynk-ws-out-write","z":"8cba898c.f9dff8","name":"Blynk write back timestamp","pin":"40","pinmode":0,"client":"fcb61c07.82a5f","x":920,"y":120,"wires":[]},{"id":"a691ac66.4c9fa","type":"change","z":"8cba898c.f9dff8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"GMT-0500 (Central Daylight Time)","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":" 2020","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":80,"wires":[["9edace0c.4737c","145c6a66.fbbfe6"]]},{"id":"51d022ea.2292dc","type":"mqtt in","z":"8cba898c.f9dff8","name":"DrivewayMotionCLOSEDetected","topic":"driveway/pir/1/close/status","qos":"2","datatype":"auto","broker":"e5102fc8.e43f8","x":130,"y":340,"wires":[["14fa6b05.119f65"]]},{"id":"daf59c63.307bd","type":"blynk-ws-out-write","z":"8cba898c.f9dff8","name":"Blynk status","pin":"41","pinmode":0,"client":"fcb61c07.82a5f","x":270,"y":540,"wires":[]},{"id":"7e1de680.ebd248","type":"file in","z":"8cba898c.f9dff8","name":"save snap from IPcam","filename":"/home/pi/photo.jpg","format":"","x":820,"y":320,"wires":[["dfd48066.b48cf","acf9dae2.472f28"]]},{"id":"bf8a4972.56c0b8","type":"inject","z":"8cba898c.f9dff8","name":"test motion","topic":"driveway/pir/1/status","payload":"motion","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":510,"y":400,"wires":[["e8288616.f6ad38","c5100061.b951","14f18072.9dc93"]]},{"id":"e8288616.f6ad38","type":"exec","z":"8cba898c.f9dff8","command":"curl \"http://192.168.199.54/tmpfs/auto.jpg\" >photo.jpg","addpay":false,"append":"-u admin:admin","useSpawn":"false","timer":"5","name":"load snapshot52","x":590,"y":320,"wires":[["7e1de680.ebd248"],[],[]]},{"id":"4006d38a.52b44c","type":"ui_template","z":"8cba898c.f9dff8","group":"cf1196c4.088ee8","name":"","order":5,"width":"6","height":"6","format":"\n \n <img width=\"100%\" height=\"100%\" alt=\"Image not found\" src=\"data:image/png;base64,{{msg.payload}}\" />\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1160,"y":320,"wires":[[]]},{"id":"dfd48066.b48cf","type":"base64","z":"8cba898c.f9dff8","name":"","action":"str","property":"payload","x":1020,"y":320,"wires":[["4006d38a.52b44c"]]},{"id":"c5100061.b951","type":"exec","z":"8cba898c.f9dff8","command":"curl \"http://192.168.199.52/tmpfs/auto.jpg\" >photo2.jpg","addpay":false,"append":"-u admin:admin","useSpawn":"false","timer":"5","name":"load snapshot54","x":590,"y":500,"wires":[["91613b9e.991ee8"],[],[]]},{"id":"91613b9e.991ee8","type":"file in","z":"8cba898c.f9dff8","name":"save snap from IPcam","filename":"/home/pi/photo2.jpg","format":"","x":800,"y":500,"wires":[["4385f9ee.774668","acf9dae2.472f28"]]},{"id":"2439fee1.6da402","type":"ui_template","z":"8cba898c.f9dff8","group":"cf1196c4.088ee8","name":"","order":6,"width":"6","height":"6","format":"\n \n <img width=\"100%\" height=\"100%\" alt=\"Image not found\" src=\"data:image/png;base64,{{msg.payload}}\" />\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1140,"y":520,"wires":[[]]},{"id":"4385f9ee.774668","type":"base64","z":"8cba898c.f9dff8","name":"","action":"str","property":"payload","x":1000,"y":520,"wires":[["2439fee1.6da402"]]},{"id":"acf9dae2.472f28","type":"change","z":"8cba898c.f9dff8","name":"Setup mail content","rules":[{"t":"set","p":"attachments","pt":"msg","to":"[{\t    \"filename\": 'photo.jpg', \t    \"content\": $$.payload,\t    \"cid\": 'some_unique_file_id'\t}]","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"Driveway Activity","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Driveway activity Detected.:<br><img src=\"cid:some_unique_file_id\"/>',<br>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":400,"wires":[["26984cda.e659c4"]]},{"id":"26984cda.e659c4","type":"e-mail","z":"8cba898c.f9dff8","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"matt@k3fab.com","dname":"email me","x":1280,"y":400,"wires":[]},{"id":"14f18072.9dc93","type":"exec","z":"8cba898c.f9dff8","command":"curl \"http://192.168.199.55/tmpfs/auto.jpg\" >photo55.jpg","addpay":false,"append":"-u admin:admin","useSpawn":"false","timer":"5","name":"load snapshot55","x":590,"y":620,"wires":[["e1e9c250.a565e"],[],[]]},{"id":"e1e9c250.a565e","type":"file in","z":"8cba898c.f9dff8","name":"save snap from IPcam","filename":"/home/pi/photo55.jpg","format":"","x":800,"y":620,"wires":[["b7254240.dc043","acf9dae2.472f28"]]},{"id":"76855f07.c449c","type":"ui_template","z":"8cba898c.f9dff8","group":"cf1196c4.088ee8","name":"","order":6,"width":"6","height":"6","format":"\n \n <img width=\"100%\" height=\"100%\" alt=\"Image not found\" src=\"data:image/png;base64,{{msg.payload}}\" />\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1140,"y":620,"wires":[[]]},{"id":"b7254240.dc043","type":"base64","z":"8cba898c.f9dff8","name":"","action":"str","property":"payload","x":1000,"y":620,"wires":[["76855f07.c449c"]]},{"id":"eba3736.c64369","type":"function","z":"8cba898c.f9dff8","d":true,"name":"combine attachments","func":"msg.payload = \"Driveway alert\";\n\nmsg.topic = \"DrivewayMotion\";\n\nmsg.attachments = [{filename: \"photo.jpg\", content: msg.File1},\n                   {filename: \"photo2.jpg\", content: msg.File2}, \n                   {filename: \"photo55.jpg\", content: msg.File3}];\n\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":1080,"y":240,"wires":[[]]},{"id":"e5102fc8.e43f8","type":"mqtt-broker","z":"","name":"localhost:1883","broker":"localhost:1883","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"cf1196c4.088ee8","type":"ui_group","z":"","name":"Driveway","tab":"7a911f8e.d7e13","order":1,"disp":true,"width":"6","collapse":false},{"id":"fcb61c07.82a5f","type":"blynk-ws-client","z":"","name":"Blynk cloud","path":"ws://blynk-cloud.com/websockets","key":"blah","dbg_all":true,"dbg_read":false,"dbg_write":false,"dbg_notify":false,"dbg_mail":false,"dbg_prop":false,"dbg_sync":false,"dbg_bridge":false,"dbg_low":false,"dbg_pins":"","multi_cmd":false,"proxy_type":"no","proxy_url":"","enabled":true},{"id":"7a911f8e.d7e13","type":"ui_tab","z":"","name":"Outside","icon":"dashboard","order":8,"disabled":false,"hidden":false}]

Make sure the pictures exist, then fill in the email account data.

[{"id":"18a6155c.b88013","type":"tab","label":"Emails","disabled":false,"info":""},{"id":"6ba72199.82865","type":"file in","z":"18a6155c.b88013","name":"","filename":"/home/pi/photo.jpg","format":"","chunk":false,"sendError":false,"encoding":"none","x":590,"y":500,"wires":[["92bf063.fc39e78"]]},{"id":"20168443.46f4ac","type":"file in","z":"18a6155c.b88013","name":"","filename":"/home/pi/photo2.jpg","format":"","chunk":false,"sendError":false,"encoding":"none","x":600,"y":560,"wires":[["92bf063.fc39e78"]]},{"id":"6b6f01f8.965eb8","type":"file in","z":"18a6155c.b88013","name":"","filename":"/home/pi/photo55.jpg","format":"","chunk":false,"sendError":false,"encoding":"none","x":600,"y":620,"wires":[["92bf063.fc39e78"]]},{"id":"2e7f1e0a.b5109a","type":"inject","z":"18a6155c.b88013","name":"Test","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":560,"wires":[["6ba72199.82865","20168443.46f4ac","6b6f01f8.965eb8"]]},{"id":"92bf063.fc39e78","type":"join","z":"18a6155c.b88013","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":830,"y":560,"wires":[["7f8eacb1.99ab9c"]]},{"id":"7f8eacb1.99ab9c","type":"function","z":"18a6155c.b88013","name":"Prepare Email","func":"msg.attachments = [{filename: \"File1.jpg\", content: msg.payload[0]},\n                   {filename: \"File2.jpg\", content: msg.payload[1]}, \n                   {filename: \"File3.jpg\", content: msg.payload[2]}];\n\n\nmsg.payload = \"Email Body Message\";\n\nmsg.topic = \"Subject Message\";\n\n\n\nreturn msg;","outputs":1,"noerr":0,"x":1000,"y":560,"wires":[["ed701e54.a400b8","def03c3c.66ad08"]]},{"id":"ed701e54.a400b8","type":"debug","z":"18a6155c.b88013","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1210,"y":520,"wires":[]},{"id":"def03c3c.66ad08","type":"e-mail","z":"18a6155c.b88013","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"","dname":"","x":1210,"y":580,"wires":[]}]
1 Like

Thank you so much / that did it. I was missing a join node, duh! I couldn't see the forest for the trees.

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