On a slightly different, but related topic.
I discovered an issue in the workaround function that I had written which uses nodemailer.createTransport to send emails. The issue caused Node-Red to crash (exit-code) and restart. (In my case during stormy weather, leading me to investigate intermittent hardware connections.)
The issue occurs if the function is called with a null msg.payload
The log below might help someone else searching for a solution to a similar problem in future.
syslog contained the following:
Apr 12 09:17:17 NR1 Node-RED[]: 12 Apr 09:17:17 - [error] [function:Send email using nodemailer] Error: No recipients defined
Apr 12 09:17:17 NR1 Node-RED[]: 12 Apr 09:17:17 - [red] Uncaught Exception:
Apr 12 09:17:17 NR1 Node-RED[]: 12 Apr 09:17:17 - [error] TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object
Apr 12 09:17:17 NR1 Node-RED[]: at new NodeError (internal/errors.js:322:7)
Apr 12 09:17:17 NR1 Node-RED[]: at PassThrough.Writable.write (internal/streams/writable.js:285:13)
Apr 12 09:17:17 NR1 Node-RED[]: at PassThrough.Writable.end (internal/streams/writable.js:567:10)
Apr 12 09:17:17 NR1 Node-RED[]: at Immediate._onImmediate (/home/pi/.node-red/node_modules/nodemailer/lib/mime-node/index.js:977:46)
Apr 12 09:17:17 NR1 Node-RED[]: at processImmediate (internal/timers.js:464:21)
Apr 12 09:17:17 NR1 systemd[1]: nodered.service: Main process exited, code=exited, status=1/FAILURE
Apr 12 09:17:17 NR1 systemd[1]: nodered.service: Failed with result 'exit-code'.