Node-RED: Send Email Notifications

This quick guide shows how to easily send emails with Node-RED. This can be a useful feature to incorporate into your home automation system for many applications. For example, to send notifications to your email if a sensor reading is above or below a certain threshold, to send readings periodically to your email, to send a notification when motion is detected, and much more.

How to Send Emails with Node-RED

Prerequisites

Before proceeding you need to have Node-RED installed. You can install Node-RED locally on your computer or on a Raspberry Pi, or on a cloud server. Check the following tutorials:

For a quick Node-RED getting started guide, take a look at the following tutorials:

Install Email Nodes

There are Node-RED Nodes you can install that make it easy to send emails using Node-RED.

Go to Menu > Manage Palette > Install. Search for node-red-node-email and install those nodes.

Node-RED install email Nodes

For more information about the nodes, you can check the following link:

Now, you should have the email nodes on your Node-RED palette.

Node-RED email nodes

Sender Email

To send emails with Node-RED you need a sender email account. We don’t recommend using your main email account to send emails using Node-RED. If something goes wrong in your flow or if by mistake you make too many requests, you can be banned or have your account temporarily disabled. So, we recommend creating a new email account to send emails or using a secondary email account.

We’ll use a Gmail.com account to send the emails, but you can use any other email provider. The receiver email can be your personal email without any problem.

Create a Sender Email Account

To create a new Gmail account for sending emails with Node-RED, go to this link.

Gmail Create a new account

Create an App Password

You need to create an app password so that Node-RED can send emails using your Gmail account. An App Password is a 16-digit passcode that gives a less secure app or device permission to access your Google Account. Learn more about sign-in with app passwords here.

An app password can only be used with accounts that have 2-step verification turned on.

  1. Open your Google Account.
  2. In the navigation panel, select Security.
  3. Under “Signing in to Google”, select 2-Step Verification > Get started.
  4. Follow the on-screen steps.

After enabling 2-step verification, you can create an app password.

  1. Open your Google Account.
  2. In the navigation panel, select Security.
  3. Under “Signing in to Google”, select App Passwords.
Create app password gmail

In the Select app field, choose mail. For the device, select Other and give it a name, for example, Node-RED. Then, click on Generate. It will pop-up a window with a password that you’ll use in Node-RED to send emails. Save that password (even though it says you won’t need to remember it) because you’ll need it later.

Generated App password gmail

Now, you should have an app password that you’ll use on Node-RED to send the emails.

Node-RED app password gmail

If you’re using a different email provider, check what you need to do to create an app password. You should be able to find the instructions with a quick google search “your email provider name + app password”.

Gmail SMTP Server Settings

If you’re using a Gmail account, these are the SMTP Server details:

  • SMTP Server: smtp.gmail.com
  • SMTP username: Complete Gmail address
  • SMTP password: Your Gmail password
  • SMTP port (TLS): 587
  • SMTP port (SSL): 465
  • SMTP TLS/SSL required: yes

Outlook SMTP Server Settings

For Outlook accounts, these are the SMTP Server settings:

  • SMTP Server: smtp.office365.com
  • SMTP Username: Complete Outlook email address
  • SMTP Password: Your Outlook password
  • SMTP Port: 587
  • SMTP TLS/SSL Required: Yes

Live or Hotmail SMTP Server Settings

For Live or Hotmail accounts, these are the SMTP Server settings:

  • SMTP Server: smtp.live.com
  • SMTP Username: Complete Live/Hotmail email address
  • SMTP Password: Your Windows Live Hotmail password
  • SMTP Port: 587
  • SMTP TLS/SSL Required: Yes

If you’re using another email provider, you need to search for its SMTP Server settings. Now, you have everything ready to start sending emails with Node-RED.

Sending an Email with Node-RED

Drag an email node to the flow.

Node-RED email node

Drag an inject node to the flow and wire it to the email. The inject node will contain the email content.

Node-RED email flow

To learn how we must configure the message for the email node, we can take a look at the email node documentation. Select the email node and then, click on the help icon in the top right corner.

Node-RED help documentation icon

You’ll get information about how to use the node.

node-red email nodes documentation

So, we must set the message content on msg.payload and the email subject on msg.topic. The recipient can be set in msg.to or in the email node (we’ll set it in the email node).

Double-click the inject node to edit its properties.

Add the email content on msg.payload. You need to set it as a String. Then, add the email subject on the msg.topic. It also must be set as a String.

Node-RED send email inject node

Now, double-click the email node to edit its properties. Insert the recipient email, the sender email, and the corresponding app password you generated previously.

Node-RED send email node

When you’re finished, click Done.

Testing the Flow

Now, deploy your application.

Node-RED deploy button

After deploying click on the left square on the inject node to trigger the email node.

Node-RED send email flow trigger

If everything went as expected, you should have a new email on your recipient account.

Gmail receive email from Node-RED

That’s it! You learned an easy way to send emails with Node-RED.

Wrapping Up

As you can see, sending emails with Node-RED is very straightforward. We showed you a simple example with an inject node. The idea is to apply this feature in real-world scenarios. We’ll publish more tutorials about this subject, so stay tuned.

If you want to learn how to send emails using the ESP32 or ESP8266 boards, you can check the following tutorials instead:

To learn more about Node-RED and Home Automation, take a look at our dedicated eBook in the link below. Learn Node-RED and InfluxDB on a Raspberry Pi to build a Home Automation System with the ESP32 and ESP8266.

Thanks for reading.



Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »

Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our newsletter!

3 thoughts on “Node-RED: Send Email Notifications”

  1. Hi, thanks for this cool tutorial.
    How if I want to send email to multiple email addresses? Is it means to put multiple email nodes too?

    Thanks.

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.