The node-red email node most commonly used is the node-red-node-email which consists of three nodes.
- A send node
- receive node
- MTA (transfer node)
Using the Send Node
This is the most commonly used node as many flows will need to send an email when a particular event occurs.
The send node using SMTP(Simple Mail Transfer Protocol) to send email. Today most email is sent encrypted.
The following screen shot show my setup using the email of my hosting provider.
You can specify the recipient in the node setup or more commonly pass it in from a preceding node.
Common ports are 465,587,25. This is what the documentation says about the ports
Use secure connection – If enabled the connection will use TLS when connecting to server. If disabled then TLS is used if server supports the STARTTLS extension. In most cases set this to enabled if you are connecting to port 465. For port 587 or 25 keep it disabled.
You can get the settings from your email provider. Here are mine:
The node accepts several parameters the most commonly used are:
- msg.payload=email body can contain HTML
- msg.topic=email subject
- msg.cc =email cc
- msg.bcc =email bcc
- msg.from =the from address
- msg.attachments = message attachments in nodemailer format
To use attachments you need to pass an array of objects as shown below:
You need to use the catch node to catch email send errors.
The error property of the message will contain the rror messages as shown below.
A mailbox is a storage area were emails are stored. A mailbox is independent of the protocol and client used to access it .
This means that multiple clients can access the same email mailbox and it can be accessed using IMAP$ or POP3 or both at the same time.
Receiving Emails IMAP
The receive node will receive email from POP3 and IMAP4 mailboxes.
IMAP4 is the more modern protocol and the one most commonly used.
It was designed so that email messages would be stored on the email server and not on the email client.
You select it from the protocol setting
As with SMTP this is usually done over an encrypted connection (SSL).
You will need to set the email server and port the details you can get from your email provider.
The settings for Ionos are shown below:
The settings tab for the node are shown below. This changes slightly for POP3.
The default setting for the node is to check for new mail every 300 seconds and to mark the mail as read.
This means that when you check again in mins you only see mail that has arrived since you last checked.
You can change this behaviour using the deposition and criteria settings.
In this mode there is no node input.
If you set the get mail property to triggered you get an input terminal and you can modify various settings. the main inputs are:
Node outputs are
msg.payload =plain text msg
msg.html=html if message is an html message or may be absent
msg.from – address of message sender.
msg.header =addition information about the message
An example message is shown below:
An IMAP mailbox can contain many folders. Some are standard folders like INBOX and others depend on the mail service provider.
Receiving Emails POP3
POP3 is the older email protocol and was designed so that email messages would be stored on the email client and not on the email server.
The default behaviour is to download the messages from the server and delete them on the server.
Most email clients offer the ability to leave them on the server but the email node doesn’t.
So the first time you connect the node-red email node to a maibox using POP3 it will delete all of the emails in the INBOX of that mailbox
Most email providers use different domain names for the IMAP and POp3 Email server and so you will need change this as well as the port. The settings for Ionos are shown below:
What is StartTLS
Opportunistic TLS (Transport Layer Security) refers to extensions in plain text communication protocols, which offer a way to upgrade a plain text connection to an encrypted (TLS or SSL) connection instead of using a separate port for encrypted communication. Several protocols use a command named “STARTTLS” for this purpose. –Wiki
Using Google Gmail
The email node is commonly used with Gmail and was the way I originally used it.
However Google have tightened their email security for IMAP4 clients and it has stopped working.
There is a work around here but I think you are probably better off choosing another email provider that uses pop3, IMAP4 and SMTP.
Google Gmail does provide support for these protocols but it is primarily an http (web based) based email service.
Applications often send alert notifications via email and so a common task is to parse the incoming message to decode it.
I have also worked on flows were meter readings have been sent via email and it was necessary to extract the address, reference and reading from the email.
If you would like me to do some examples then leave a note in the comments section
Video-How to Send Email and SMS Notifications
Related Tutorials and Resources
- Using the Status Node
- Node-Red HTTP Request Node for Beginners
- Using the Node-Red Function Node- Beginners Guide