Email Node: Flow stops if no unread emails


I have a flow that fetches unread emails (Report from Smart Meter Texas) once per day, parses the CSV attachment and stores the data in a database. The flow works fine but if there are no unread emails (report was not received), the flow does not proceed. I want to send out an alert if there are no unread emails but not sure how I can do that.

Below is how my email node is configured and a screenshot of the flow:

The debug node "Unread Email Return" has nothing if there is no unread email and the flow does not get to the "Only if meter readings" switch node. Any suggestions on how I could send an alert if there are no unread emails? Thanks for your help.

One way would be:

  • Disconnect at your red arrow

  • Connect the email node to a change node that sets the msg in a context/flow variable and stop.

  • Create new injection node 1 min later then your current injection node

  • Connetct this to a switch node if the flowvariable = null >> route to what ever you want to do (no message). If not null > change node to set the variable back to null (for the next time, otherwise you'll use the old msg next time) > route into the "only if meter readings" node.

more info on context variable: Working with context : Node-RED

1 Like

Thanks so much - I was thinking about something along those lines. This helps confirm that approach.

I believe this is the intended behavior, of the node. So you will likely want to create a timeout.

Here is an example that should make it really simple:

[{"id":"0743122b2439fa37","type":"inject","z":"45d8e1463946ef85","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pass","x":230,"y":300,"wires":[["0e408a2aab18b784","26a55044a28e7bfd"]]},{"id":"26a55044a28e7bfd","type":"trigger","z":"45d8e1463946ef85","name":"10 sec timeout","op1":"","op2":"No unread emails found","op1type":"nul","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":520,"y":380,"wires":[["bc2a0140dc3f0cd8"]]},{"id":"1ac67b2a37f62e51","type":"change","z":"45d8e1463946ef85","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":320,"wires":[["26a55044a28e7bfd"]]},{"id":"0e408a2aab18b784","type":"function","z":"45d8e1463946ef85","name":"email node","func":"// this is just a placeholder\nif (msg.topic === \"pass\") {\n    node.send({ \"payload\": \"Unread email found\" });\n};\nif (msg.topic === \"fail\") {\n    // commented out so no message is sent if unread email is not found\n    //node.send({\"payload\":\"No unread email found\"});\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":260,"wires":[["1ac67b2a37f62e51","bc2a0140dc3f0cd8"]]},{"id":"a4899a92e802be9a","type":"inject","z":"45d8e1463946ef85","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"fail","x":230,"y":340,"wires":[["0e408a2aab18b784","26a55044a28e7bfd"]]},{"id":"bc2a0140dc3f0cd8","type":"debug","z":"45d8e1463946ef85","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":320,"wires":[]}]
1 Like

you could also use a timer node from your injection node in parallel to the get unread emails and then use the rest as described.

1 Like

Thanks - this worked perfectly!

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