Node-RED Send Email Alerts and Notifications

In this user guide, we will show you how to send email alerts with Node-RED. It is very handy and practical to include email notifications in IoT projects where sensor reading monitoring, motion detection, message notifications and alarm alerts. After following this tutorial, you will be able to easily send emails to a recipient account using Node-RED in a fairly easy manner.

Node-RED Send Email Alerts and Notifications

Before starting this tutorial, you should have Node-RED installed. You can install Node-RED on your computer or on a Raspberry Pi. Check the following tutorials:

SMTP Server

Simple Mail Transfer Protocol server or SMTP server for short is responsible for sending and receiving emails between the senders and the receivers. Each email provider e.g., Gmail, Yahoo, Hotmail, Outlook, etc. has a unique SMTP address and settings. These can usually be accessed through your account settings. Whenever a user sends an email, the SMTP server processes it and sends it to the particular server accordingly. The recipient’s email service provides obtains the message which then turns up in the recipient’s inbox.

Setting up Sender Gmail Account

To send emails we would require two email accounts. One for the sender and one for the recipient. You can use your own email account as the sender account but it is recommended to create a new one just in case something goes wrong. For this article, we will use Gmail as the primary email provider. You can use any other provider as your preference.

Creating a new account in Gmail (Sender side)

Firstly, type in your browser search tab and press enter. This will open the main page. Click ‘Create an Account as highlighted in the red rectangular box.

Setting new gmail account 1

Now type all the relevant information and click ‘Next’. You can give in details according to your preference.

Proceed with all the steps accordingly to create your account successfully.

Generate App Password

After your account is created, we have to generate the App password in order for Node-RED to send emails from this account. This password will allow the device to access the sender Gmail account.

The first step is to turn the 2 step verification on. Head over to the following link which opens your Google Account. Head over to Security and go to ‘Signing in to Google.’ Then click 2-Step Verification and Get Started.

After following a number of steps, you will reach the final step where you will be asked to turn on the 2-Step verification. Click ‘TURN ON’ to proceed.

Node-RED send email alerts turn on 2-step verification

Note that 2-Step Verification is now On.

Node-RED send email alerts turn on 2-step verification 2

Now we will move ahead and generate the app password. Head over to Security > Signing in to Google > App Passwords.

Select app as ‘Mail’ and device as ‘Other.’ Give a name to your device according to your preference. We have set it as ‘Node-RED.’ Finally, click the GENERATE button to obtain the App password.

Node-RED send email alerts generate app password 1

You will obtain the app password for your device. Save it and then click ‘DONE.’

Node-RED send email alerts generate app password 2

Here you can view that the device Node-RED password has been successfully created.

Node-RED send email alerts generate app password 3

SMTP Server Settings for Gmail Server

You can view the Gmail server settings as shown below. Knowing this is important because we have to include them in our program code to configure our account properly.

  • Server:
  • Sender username: the complete email address of the sender account.
  • Sender password: the password of the sender account
  • Server port (TLS): 587
  • Server port (SSL): 465
  • SMTP TLS/SSL required: yes

If you are using a different email provider e.g., outlook or yahoo you can access its SMTP server settings online.

Setting up Node-Red for Email Alerts

We will use Node-Red to send emails. In order to get started with Node-Red on Raspberry Pi, refer to the guide:

To access Node-RED, we need the IP address of our Raspberry Pi and the port number on which Node-RED is accessible. By default, it starts on port 1880. Open any web browser and enter the RPI IP address followed by the port number.

Creating Flow to Send Email

This will open the Node-RED interface. You can start creating the flow.

access Node-RED

Head over to Menu > Manage Palette > Install. Type node-red-node-email in the search bar and press enter. Install the Node-RED nodes to send and receive simple emails.

Node-RED send email alerts install email nodes

After the installation completes, the email nodes will be present in the palette as shown below:

Node-RED send email alerts install email nodes 2

Now drag an inject node and email node to the flow as shown below:

Node-RED send email alerts add nodes to the flow

Now double click the inject node to edit its properties as shown below.

msg.payload holds the body of the email in the form of a string. Specify the contents that you want to send. ‘This is a test email sent from Node-RED’ is the email body that we want to send. Similarly, msg.topic is the email subject which we have set as ‘Node-Red Email Alert.’ Click the Done button when you have made the changes.

Node-RED send email alerts edit inject node

Now double click the email node and edit its properties as well.

Specify the recipient and sender email addresses. Moreover, enter the app password that we obtained previously for Node-RED to send emails. Click the Done button after making all the changes.

Node-RED send email alerts edit email node


Wire the nodes as shown below:

Now deploy the changes by clicking the Deploy button found at the top.

Node-RED send email alerts join nodes and deploy

Now click the left square on the inject node to send the email. You will receive a notification on the top showing that it was successfully injected.

Node-RED send email alerts testing the flow

Open the recipient’s email account. You will already have received the email from the sender account using Node-RED.

Node-RED send email alerts demo

You may also like to read:

Leave a Comment