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.
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:
- Install Node-RED on Raspberry Pi (works on RPI OS 64-bit)
- Access Node-RED Dashboard from Anywhere using Digital Ocean
For a quick Node-RED getting started guide, take a look at the following tutorials:
- Getting Started with Node-RED on Raspberry Pi
- Getting Started with Node-RED Dashboard on Raspberry Pi
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.
For more information about the nodes, you can check the following link:
Now, you should have the email nodes on your Node-RED palette.
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.
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.
- Open your Google Account.
- In the navigation panel, select Security.
- Under “Signing in to Google”, select 2-Step Verification > Get started.
- Follow the on-screen steps.
After enabling 2-step verification, you can create an app password.
- Open your Google Account.
- In the navigation panel, select Security.
- Under “Signing in to Google”, select App Passwords.
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.
Now, you should have an app password that you’ll use on Node-RED to send the emails.
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.
Drag an inject node to the flow and wire it to the email. The inject node will contain the email content.
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.
You’ll get information about how to use the node.
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.
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.
When you’re finished, click Done.
Testing the Flow
Now, deploy your application.
After deploying click on the left square on the inject node to trigger the email node.
If everything went as expected, you should have a new email on your recipient account.
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:
- ESP32 Send Emails using an SMTP Server: HTML, Text, and Attachments (Arduino IDE)
- ESP8266 NodeMCU Send Emails using an SMTP Server: HTML, Text, and Attachments (Arduino)
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.
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.
Yes.
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.
Yes, that’s right.
Thanks for the suggestion.
Regards,
Sara
Hey Gerin, can you provide some example? How can I trigger the iteration?
Thx
I’m super following this tutorial and discussions.
Hi, I am getting an error like “Error: connect ETIMEDOUT 40.100.137.242:465”. What can i do to fix that??
Hi, I am getting an error like “Error: connect EACCES 74.125.24.109:465″. What can i do to fix that??
Hi.
Double-check the email credentials.
You should use the email app password, and not the email password.
Regards,
Sara
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…
Hi.
What email provider are you using?
Regards,
Sara
SMTP.domin.com.
Try to use a gmail account instead.
I’m not sure what are the details for that email provider.
Regards,
Sara
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?
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