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.
Configuration
Section titled “Configuration”All fields support templatization — use ${metadataKey} and $[dataKey] to substitute values dynamically.
Sender
Section titled “Sender”- From — sender email address (e.g.,
[email protected]).
Recipients
Section titled “Recipients”- 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 and body
Section titled “Subject and body”- 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.
Date formatting in subject and body
Section titled “Date formatting in subject and body”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">.
Message processing algorithm
Section titled “Message processing algorithm”- Receive the incoming message.
- Substitute all template patterns in
From,To,Cc,Bcc,Subject,Body, andBody type template. - Process
%d{...}date-format patterns inSubjectandBodyusing the message processing timestamp andemailTimezonemetadata if present. - Check metadata for
attachments,reports, andimageskeys and include in the output. - Determine the final body type (
html: true/false). - Construct a new message of type
SEND_EMAILwhose data is a JSON object containing all email fields; route viaSuccess.
Output connections
Section titled “Output connections”| Connection | Condition |
|---|---|
Success | A SEND_EMAIL message with fully resolved email parameters. |
Failure | An error occurred during transformation. |
Examples
Section titled “Examples”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 } }
{ "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:
{ "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:
[email protected]— 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}— readsisHtmlfrom 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;"> <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;">— The ThingsBoard :)</span></td> </tr> </tbody> </table> </td> </tr> </tbody></table>Incoming:
- Metadata:
{ "userEmail": "[email protected]", "isHtml": "true" }
Outgoing SEND_EMAIL data:
{ "cc": null, "bcc": null, "subject": "ThingsBoard Notification", "body": "<table class=\"main\" ...>...</table>", "attachments": null, "reports": null, "images": null, "html": true}${userEmail} resolved to [email protected]; ${isHtml} resolved to "true" → html: true in output.
JSON schema
Section titled “JSON schema”{ "$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'." } }}