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.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

15 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
    • I think you can achieve this with only a single email node as long as the STMP settings remain the same. I noticed the following in this article: “The recipient can be set in msg.to or in the email node”. This means that instead of hardcoding it in the node, if you have an array of recipients you can iterate through it and in each iteration overwrite the msg.to property. After you send the mail, loop back into the array to send to the next user.

      Reply
  2. Hi, I am getting an error like “Error: connect EACCES 74.125.24.109:465″. What can i do to fix that??

    Reply
    • Hi.
      Double-check the email credentials.
      You should use the email app password, and not the email password.
      Regards,
      Sara

      Reply
  3. Hi – I get the error:
    Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1533:34)
    at TLSSocket.emit (node:events:537:28)
    at TLSSocket._finishInit (node:_tls_wrap:947:8)
    at ssl.onhandshakedone (node:_tls_wrap:728:12)
    when I click on inject.

    If I turn off Check server certificate is valid then it works but this makes me nervous. Node Red is running in a Raspberry PI setup by one of the Random Nurd tutorials…

    Suggestions/fixes?

    Thanks,
    Stephen…

    Reply
  4. When I was generating the app password, it said “There was an error generating your app password”. Is there a way to do it without?

    Reply
    • Hi.
      Gmail only allows you to use app passwords to login in your accounts using third-party services.
      There must be some issue or configuration on your google account.
      Regards,
      Sara

      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.