Explore ThingsBoard tutorials and guides.

Send email on alarm

This Tutorial is to show you how to send an Email to the user using the Rule Engine.

Use case

In this tutorial we will implement the use case from the tutorial: create & clear alarms:

Let’s assume your device is using DHT22 sensor to collect and push temperature readings to ThingsBoard. DHT22 sensor is good for -40 to 80°C temperature readings.We want to generate Alarms if temperature is out of good range and send the email when the alarm was created.

In this tutorial we will configure ThingsBoard Rule Engine to:


We assume you have completed the following guides and reviewed the articles listed below:

Message flow

In this section, we explain the purpose of each node in this tutorial:

Configure Rule Chains

In this tutorial, we used Rule Chains from create & clear alarms tutorial. We modified Rule Chain Create & Clear Alarms by adding nodes that was described above in the section Message flow
and renamed this rule chain to: Create/Clear Alarm & Send Email.

The following screenshots show how the above Rule Chains should look like:



Download the attached json file for the Create/Clear Alarm & Send Email rule chain.

The following section shows you how to modify this rule chain from scratch.

Modify Create/Clear Alarm & Send Email

Adding the required nodes

In this rule chain, you will create 3 nodes as it will be explained in the following sections:

Node A: Transform Script

 metadata.temperature = msg.temperature;
 return {msg: msg, metadata: metadata, msgType: msgType};


Node B: To Email


Node C: Send Email

Please note that at Demo Server was already configured SendGrid provider as system SMTP.

The instructions of how to configure these settings will be explained in the section below.


Chain configuration is finished and we need to save it.

Configuring system SMTP settings

In this section, we explain to you how to configure system SMTP settings and try to send the test email:

If you have permission to log in to ThingsBoard, with using system administrator account you can customize SMTP settings and send Test Email.


If the System SMTP configure all right: you will see a pop-up message as shown in the screenshot above.
System SMTP settings configuration is finished. Don’t forget to press button Save.

If you can’t access to the account of the System administrator you could configured SMTP settings right in the node but you can’t be checked that email was successfully sent.

Post telemetry and verify

For posting device telemetry we will use the Rest APIs, Telemetry upload APIs. For this we will need to copy device access token from then device Thermostat Home.


Lets post temperature = 180. Alarm should be created:

curl -v -X POST -d '{"temperature":180}' http://localhost:8080/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"

**you need to replace $ACCESS_TOKEN with actual device token**

You should understand that message won’t be sent to the email when the alarm was updated, only in the case when alarm will be created.

Finally we can see that email was received with correct values. (Please check your spam folder if you did not receive any email)


Also, you can see the more information about how to:

Please refer to the first link under the See Also section to see how to do this.

See Also

Next steps