Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load content from other services such as the Google site search. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics, Microsoft Clarity).

Show us which of our ad campaigns bring visitors to the site and remember the campaign or partner link you arrived from (Google Ads, LinkedIn, Meta, partner program). We do not use these cookies to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

© 2026 The ThingsBoard Authors
22.5k Try for free

ThingsBoard Cloud

Choose your data region

Your data stays in the region you choose, for residency and compliance. No credit card required.

Rather run it yourself? Install on your own servers

To Email

Use this node to transform an incoming message into an email-ready SEND_EMAIL message — for example, converting a high-temperature alarm into a formatted notification email with device name and reading values substituted from message metadata and data. This node constructs the email parameters; the actual dispatch is handled by a downstream Send Email node.

All fields support templatization — use ${metadataKey} and $[dataKey] to substitute values dynamically.

  • From — sender email address (e.g., alarms@yourcompany.com).
  • To — comma-separated list of primary recipient addresses.
  • Cc — comma-separated list of CC recipients (optional).
  • Bcc — comma-separated list of BCC recipients (optional).
  • Subject — email subject line. Supports templatization and date formatting (see below).
  • Mail body type — how the body is rendered:
    • Plain text — body sent as-is unformatted text.
    • HTML — body rendered as HTML.
    • Use body type template — body type determined at runtime from Body type template (resolves to "true" for HTML or "false" for plain text).
  • Body — main email content. Supports templatization and date formatting.

Use %d{<pattern>} to insert the message processing timestamp as a formatted date string, where <pattern> is a Java SimpleDateFormat pattern:

  • Device Alert at %d{yyyy-MM-dd HH:mm:ss} → Device Alert at 2024-03-15 10:30:00

If the incoming message metadata contains emailTimezone with a valid timezone ID (e.g., Europe/Kyiv), that timezone is applied to the date formatting. Otherwise the server’s default timezone is used.

Attachments and embedded images (via metadata)

Section titled “Attachments and embedded images (via metadata)”

The node reads these optional metadata keys from the incoming message:

  • attachments — comma-separated Blob Entity UUIDs to attach.
  • reports — comma-separated report UUIDs to attach.
  • images — JSON map of Content-IDs to data URLs, for embedding images in HTML: {"logo": "data:image/png;base64,..."}; reference in body as <img src="cid:logo">.
  1. Receive the incoming message.
  2. Substitute all template patterns in From, To, Cc, Bcc, Subject, Body, and Body type template.
  3. Process %d{...} date-format patterns in Subject and Body using the message processing timestamp and emailTimezone metadata if present.
  4. Check metadata for attachments, reports, and images keys and include in the output.
  5. Determine the final body type (html: true/false).
  6. Construct a new message of type SEND_EMAIL whose data is a JSON object containing all email fields; route via Success.
Connection Condition
Success A SEND_EMAIL message with fully resolved email parameters.
Failure An error occurred during transformation.

Example 1 — Alarm email with dynamic subject and body

Section titled “Example 1 — Alarm email with dynamic subject and body”

Incoming metadata: { "deviceName": "TempSensor-A1", "deviceType": "Temperature Sensor" }

Incoming data (alarm object, excerpt): { "details": { "temperatureValue": 95.5, "temperatureThreshold": 90 } }

{
"fromTemplate": "alarms@yourcompany.com",
"toTemplate": "example@yourcompany.com",
"ccTemplate": null,
"bccTemplate": null,
"subjectTemplate": "${deviceType} - ${deviceName}: High temperature alarm",
"mailBodyType": "false",
"bodyTemplate": "A temperature of $[details.temperatureValue] exceeds the threshold of $[details.temperatureThreshold]."
}

Outgoing SEND_EMAIL data:

{
"from": "alarms@yourcompany.com",
"to": "example@yourcompany.com",
"cc": null,
"bcc": null,
"subject": "Temperature Sensor - TempSensor-A1: High temperature alarm",
"body": "A temperature of 95.5 exceeds the threshold of 90.",
"html": false
}

Subject substituted ${deviceType} and ${deviceName} from metadata; body substituted $[details.temperatureValue] and $[details.temperatureThreshold] from data.

Example 2 — HTML body with dynamic recipient and body-type selection

Section titled “Example 2 — HTML body with dynamic recipient and body-type selection”

Configuration:

  • From: no-reply@yourcompany.com — static sender address
  • To: ${userEmail} — recipient resolved from message metadata at runtime
  • Subject: ThingsBoard Notification — static subject line
  • Mail body type: Use body type template — body type (HTML or plain text) determined at runtime from the Body type template field below
  • Body type template: ${isHtml} — reads isHtml from metadata; "true" → HTML output, "false" → plain text output
  • Body: HTML template below
<table class="main" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; box-sizing: border-box; border-radius: 3px; width: 100%; background-color: #f6f6f6; margin: 0px auto;" cellspacing="0" cellpadding="0" bgcolor="#f6f6f6">
<tbody>
<tr style="box-sizing: border-box; margin: 0px;">
<td class="content-wrap" style="box-sizing: border-box; vertical-align: top; margin: 0px; padding: 20px;" align="center" valign="top">
<table style="box-sizing: border-box; border: solid 1px #e9e9e9; border-radius: 3px; margin: 0px; height: 127px; padding: 20px; background-color: #ffffff; width: 600px; max-width: 600px !important;" width="600" cellspacing="0" cellpadding="0">
<tbody>
<tr style="box-sizing: border-box; margin: 0px;">
<td class="content-block" style="color: #348eda; box-sizing: border-box; border-radius: 6px; vertical-align: top; margin: 0px; padding: 0px 0px 20px; width: 839px;" valign="top">
<h2>Test message using 'to email' rule node</h2>
</td>
</tr>
<tr style="box-sizing: border-box; margin: 0px;">
<td class="content-block" style="box-sizing: border-box; vertical-align: top; margin: 0px; padding: 0px 0px 20px; width: 600px;" valign="top"><span style="color: #000000;">This email is indicating that your outgoing mail settings were set up correctly.</span></td>
</tr>
<tr style="box-sizing: border-box; margin: 0px;">

Incoming:

  • Metadata: { "userEmail": "johndoe@thingsboard.io", "isHtml": "true" }

Outgoing SEND_EMAIL data:

{
"from": "no-reply@yourcompany.com",
"to": "johndoe@thingsboard.io",
"cc": null,
"bcc": null,
"subject": "ThingsBoard Notification",
"body": "<table class=\"main\" ...>...</table>",
"attachments": null,
"reports": null,
"images": null,
"html": true
}

${userEmail} resolved to johndoe@thingsboard.io; ${isHtml} resolved to "true" → html: true in output.

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "TbMsgToEmailNodeConfiguration",
"type": "object",
"required": ["fromTemplate", "toTemplate", "subjectTemplate", "bodyTemplate", "mailBodyType"],
"additionalProperties": false,
"properties": {
"fromTemplate": { "type": "string" },
"toTemplate": { "type": "string" },
"ccTemplate": { "type": "string" },
"bccTemplate": { "type": "string" },
"subjectTemplate": { "type": "string" },
"bodyTemplate": { "type": "string" },
"mailBodyType": { "type": "string", "enum": ["false", "true", "dynamic"] },
"isHtmlTemplate": { "type": "string", "description": "Template for dynamic body type; resolves to 'true' or 'false'." }
}
}