Adapting Pac Control SendEmail to Node-Red

The node-red email posts have been timely. I have my node-red setup to send the email message as setup by/for PAC Control SendEmail command. The message is built from a String Table (In Pac Control) like such:

arrstrBody[0]   = strFacility;                                           // Subject line
  arrstrBody[1]   = " ";                                                   // Body starts here
  arrstrBody[2]   = " ";                              
  arrstrBody[3]   = "TEST EMAIL" + CRLF;
  arrstrBody[4]   = strMonth + "/" + strDay + "/" + strYear + " - at - " + strHour + ":" + strMinute + CRLF + CRLF;
  arrstrBody[5]   = " ";
  arrstrBody[6]   = " ";
  arrstrBody[7]   = " ";
  arrstrBody[8]   = " ";
  arrstrBody[9]   = " ";
  arrstrBody[10]  = strFacility;
  arrstrBody[11]  = " ";

It arrives from PAC Control like this:
Pac Control email

From Node-Red like this:
Node-Red email

How do I filter out the empty table elements and setup the carriage returns/body format/etc.? This is just a test email and the different elements might or might not be filled at other times with other information.

There’s a lot of ways you could go about this; the most obvious way would be to just create a new empty array, loop through arrstrBody, and then only add to the new array if the arrstrBody element is NOT " ".

Another option is to use the .filter() array function and hand in the condition you want to filter by. It’s a little bit more difficult to read, but it would be a one-line solution:

data = arrstrBody.filter(x => x !== " ");

This will filter arrstrBody by the function x !== " " and only add x to data when it’s not a space character.

1 Like