How to send an image from mqtt in an email

Hi mates, im thinking on send an array coded in base64 to an email direction but only when i press a button. How could i do it?

Using switch or function?

Than you very much

It depends. Where is the array coming from?

Actually forget where it is coming from and replace that with an inject. That starts a msg going thru a flow, but what you want to do is halt that message until another msg is send by pressing a button. That means you need to join the two messages or use a gate (see node-red-contrib-simple-gate or
node-red-contrib-queue-gate) that is controled by the switch.

Next question is, what if another data message comes in? Should it pass if the switch is still open? Should the switch close after one msg goes thru?

Laying out the logic in english will help you build your flow easier.

Hi Sir. I want to send via email an image which has been decode to Base64 using base64 node,
but only when i press a button.

So i should use a node with two input, the button and the base64 output, and when i click de button send the base64 output.

which bit are you stuck on?

no such thing. a node can only have 1 input.

Use an inject (or dashboard button) --> set payload to your image data --> send to email.

Question - is the image dynamic or hard coded/fixed? That makes things a little trickier and where I suspect you are falling down.

Ok first of all im using a gate now, and it seems to work, but the email that i receive is a stuff like this : img_datasrc ..... and a lot of words.

How could i get the image and not the code ? Im a bit confused

Try setting msg.attachements. Here as an example (there are tons of threads on this forum about "email image") I'm certain one of them will get you going.

Examples can not help me, because they are running node-red on the rpi and they use de camerapi node. Im just taking images from mqtt and codifying it to base64 and displaying in the dashboard pictures every 2 second (like a stream). And i want to take a simple picture and send it to my gmail account. Im using the correct flow but dont know how to use attachements.

click on the email node then go to the Info tab in the sidebar. Scroll to the bottom and read about msg.attachments

Sure the examples help you - you adapt them. Just because someone hasnt done it before they ceraintly have send images, they have converted buffers to base64 and back.

So taking this thread

I made this...
image

and received this in my inbox...

sample flow (note i deleted the email node for privacy)...

[{"id":"e73e2624.4459a8","type":"inject","z":"e360ac5b.0ab79","name":"base 64 image","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"NR Test image","payload":"iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAABmJLR0QA/wD/AP+gvaeTAAALuUlEQVR4nO3deYxdVR3A8e90hS62laXQFoQoCIhgURDBjcW4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u4wQ940AXlLYd1nt/UNEV3oe0dpPxAAZEzam1xMdthtKIHUTs3tvIh9IdVuISYHfJR6rPYaYLFjdDN1ItGZfIWY/V0oBMJQxyLNENxSigh/QKK8G/aXEQ5X2nkUE8g205qztSmuK/4gzQIZuuAKp+rycSCj0EN25aURXZjX54HqCGA9V2btq3tZQWpDVtfc/oe9jwQAvJ56LOSGzbzeReIFIi9+c3m8mguRR4unF0oTOYTUW/3+QHV0ukJqfBzpGyrVI44gg2UBcqd9FZMGqANqTmN6yL5EU6Ka/O4jKTTqfxZTnZDWdB1yZ3p9JKwVedxgxh23E2YKMPsPdIi0kxjy51mcj8e971e9jzCWSEJWniSzeteRbjLoraT04Bp27dyPOFmTHt71bpLojiXtDRxD/sN74tN/dRBau+WzI94GPNNZtTuc8Ku6kGyCqDCSQZhKZtk6BVD2d2ckHiKcL67MbNlO+MTrsDBAN1vYOpHGMktYDDBBtH+No3cGfmpa5zzsTwVIlDDakz6toTbQcUQ7StT30EJW9+W91NY0nH0D+72CSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJOkF43+GSQModXZh1QAAAABJRU5ErkJggg==","payloadType":"str","x":160,"y":60,"wires":[["e5f61250.26cb4"]]},{"id":"e5f61250.26cb4","type":"base64","z":"e360ac5b.0ab79","name":"","action":"","property":"payload","x":320,"y":60,"wires":[["604a8eaf.6d4ac","d6ca2446.6053c8"]]},{"id":"604a8eaf.6d4ac","type":"change","z":"e360ac5b.0ab79","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\": 'image_' & $replace($now(),\":\",\"_\") & '.jpg', \t    \"content\": $$.payload,\t    \"cid\": \"\" & cid & \"\"\t}]","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"See attached image","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"'<img src=\"cid:' & cid & '\"/>'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":180,"y":120,"wires":[["58495115.e70dc","e7e50356.464ba"]]},{"id":"58495115.e70dc","type":"debug","z":"e360ac5b.0ab79","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":170,"y":200,"wires":[]}]
1 Like

I have just done your flow, but i still without getting the image , i dont know if i am useless or if your code doesnt work on my setup

  • after MQTT in node, add a change node (set flow.lastimage to msg.payload)
    • this will store the base64 image in flow.lastimage for later
  • connect the button to a change node (set msg.payload to flow.lastimage) then to a base64 node then to the "Flow 3" node

Add DEBUG nodes to every output and give them all unique names

After the node "flow 3" attach a DEBUG (set to show complete message).

Expand the DEBUG output and show us whats happening.

Open the context viewer and show us what is in flow.lastimage

I dont know how to use debug panel in a properly way but im trying to do my best, im new on this platform sorry ;(

Ok so do this...

  1. Delete the bottom base64 node and connect the "set msg.payload" node to the "flow3" node and the debug "A" node.
  2. Move the top "set flow.lastimage" AFTER the top base64 node

Try again. Post screenshots again.

Ps. Working without the debug nodes is like walking with a blindfold on and 2 hands tied behind your back. Watch this playlist - it's not long. After 30 minutes you will be an expert. https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6

2 Likes

Like this sir? Thank you for your time, you are helping me a lot! I tried but i didnt get the image

No. You have deleted your button. Nothing will trigger it.

Yes true, i have just added it

And the debug shows what?

Same than before i believe