Search code examples
node-red

What to put in msg.criteria for fetching emails in Node-RED email node?


I have two flows using the node-red-node-email node in Node-RED.

The first one uses predefined value for fetching all emails (Criteria: All). It works properly and fetches two emails I have in my Inbox:

flow 1

The second one should emulate the same, but thru specifying msg.criteria:

I created a flow with a change node setting the value.

The info page for the email module refers to a doc page for another module and does not give a clear example, but I assumed I should add a string value of [ ALL ]. Here's the relevant part of the change module:

"rules": [
    {
        "t": "set",
        "p": "criteria",
        "pt": "msg",
        "to": "[ 'ALL' ]",
        "tot": "str"
    }

In result the email node changes to connecting then to fetching and remains in this state. The Node-RED web server does not respond for a while.

flow 2

I also tried specifying msg.criteria as a JSON object the following way (in result I get an "Invalid 'to' JSON property" in debug):

"rules": [
    {
        "t": "set",
        "p": "criteria",
        "pt": "msg",
        "to": "[ 'ALL' ]",
        "tot": "json"
    }
],

or the following way (in result I have no response at all; the email node does not even go to connecting state):

"rules": [
    {
        "t": "set",
        "p": "criteria",
        "pt": "msg",
        "to": "{ [ 'ALL' ] }",
        "tot": "json"
    }
],

What type should msg.criteria be and what data should it contain to fetch all emails (and by extension other criteria)?


Solution

  • As I mentioned in my second comment, this is most likely to do with how you set up the change node with the JSON array.

    The following change node config works as expected.

    enter image description here

    Note that ALL is wrapped with double quotes, not single quotes. This is important as the Change node throws an error when single quotes are set and doesn't actually add the field to the msg object.