Emailing image from IP camera

Hello,

I am using the following to email an image from an IP camera. Kindly supplied by a user on the forum.

Works well when viewing on outlook but when viewing on iphone the image does not always update as the file name is the same as the previous one. Is there a way to randomly change the filename of the image to alleviate this?

[{"id":"b0839d62.4385d","type":"inject","z":"707d0adc.1fe6f4","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":174.4444580078125,"y":575.5555419921875,"wires":[["f4929d12.117b1"]]},{"id":"7652ccef.dd5714","type":"e-mail","z":"707d0adc.1fe6f4","server":"","port":"","secure":false,"name":"","dname":"Send mail","x":963.4444713592529,"y":574.5555458068848,"wires":[]},{"id":"f4929d12.117b1","type":"http request","z":"707d0adc.1fe6f4","name":"Get image","method":"GET","ret":"bin","url":"http://192.168.9.111/snap.jpeg","tls":"","x":367.69056510925293,"y":575.8446083068848,"wires":[["e8959f8e.4af228"]]},{"id":"e8959f8e.4af228","type":"change","z":"707d0adc.1fe6f4","name":"Flow 3 : Setup mail content","rules":[{"t":"set","p":"attachments","pt":"msg","to":"[{\t    \"filename\": 'camera_snapshot.jpg', \t    \"content\": $$.payload,\t    \"cid\": 'some_unique_file_id'\t}]","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"Visitor DC Yard","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"<img src=\"cid:some_unique_file_id\"/>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":636.4444713592529,"y":575.055606842041,"wires":[["7652ccef.dd5714"]]},{"id":"7e8d23f7.053e34","type":"http in","z":"707d0adc.1fe6f4","name":"","url":"/fanvilyard","method":"get","upload":false,"swaggerDoc":"","x":180.68665885925293,"y":657.5555458068848,"wires":[["f4929d12.117b1","d7bf3f58.0703c8"]]},{"id":"d7bf3f58.0703c8","type":"http response","z":"707d0adc.1fe6f4","name":"","statusCode":"","headers":{},"x":348.68665885925293,"y":662.5555458068848,"wires":[]}]

Thanks
James

Usually one would use a timestamp instead - should work until the invention of time machines :slight_smile:

If you read the Email nodes info panel it will explain where in the msg.object the filename is located.

You can therefore provide the Email node with whatever you want in the message you supply it. This is easily achieved using a function node or a change node

Thanks.

Would you be able to advise how I would insert a timestamp into this flow?

Cheers
James

This is easily achieved using a function node or a change node

I would suggest you to try it for yourself - if it does not work: change the filename part to:

"filename": 'door_' & $replace($now(),":","-") & '.jpg'

Thanks.

That works for the filename however the iphone is still showing previous images, could it be the "cid": 'some_unique_file_id' part that is causing issues?

Cheers
james

Maybe - would be worth to give it a try...

This is where I'm slightly out of my depth!

Looking at the change node in the original flow, the initial json element appears to take the file, rename it with the timestamp then associate it with the cid:'some_unique_file_id'

The final part of the change node references the cid:'some_unique_file_id' and places it in the body of the email. If I remove that part the image comes in as an attachment, albeit an up to date one, so this is where the issue is happening.

How would I dynamically change the CID to be the same in both parts of the process?

Thanks for your help!

James

I modified the change node to show you a possible way:

[{"id":"f508aa8.70f5358","type":"change","z":"c421dfeb.3e752","name":"Flow 3 : Setup mail content","rules":[{"t":"set","p":"cid","pt":"msg","to":"","tot":"date"},{"t":"set","p":"attachments","pt":"msg","to":"[{\t    \"filename\": 'door_' & $replace($now(),\":\",\"_\") & '.jpg', \t    \"content\": $$.payload,\t    \"cid\": \"\" & cid & \"\"\t}]","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"Visitor DC Yard","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"'<img src=\"cid:' & cid & '\"/>'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2531.5,"wires":[["afd70e5b.5f155"]]}]

Thats perfect! Works a treat.

Thank you for your help. Very much appreciated.

Cheers
James