> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Email Connector

> Send templated email notifications and alerts from MQTT messages over SMTP

## Email Overview

The `EMAIL` connector sends templated emails in response to MQTT messages. It's the simplest way to turn a broker event — a critical alarm, a daily report, a user notification — into a message that reaches a person's inbox.

> [!TIP]
>
> **Like an auto-reply rule in your mailbox.** When a message lands on a topic you're watching, the connector fills in a template and sends the email for you — no manual step required.

### When to use it

* Alert an operations team the moment a critical alarm fires.
* Email a stakeholder a daily or shift report.
* Notify an individual user using an address pulled from the message payload.

***

Let's look at how to define an email connector, starting with the most common scenarios.

## Quick Start

> [tab] Critical alert
>
> Send an immediate alert to a fixed team address when a critical event arrives:
>
> ```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> DEFINE CONNECTOR CriticalAlerts WITH TYPE EMAIL
>     ADD SMTP_CONFIG
>         WITH HOST "smtp.gmail.com"
>         WITH PORT '587'
>         WITH USERNAME "alerts@company.com"
>         WITH PASSWORD "app-password-here"
>         WITH USE_TLS "true"
>     ADD EVENT criticalNotify
>         WITH SOURCE_TOPIC "alerts/critical/+"
>         WITH TEMPLATE_PATH "/templates/critical_alert.html"
>         WITH SUBJECT "CRITICAL: {value.json.alert_type}"
>         WITH RECIPIENT "ops-team@company.com"
> ```

> [tab] Dynamic recipient
>
> Send to an address taken from the message payload:
>
> ```lot wrap  theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> DEFINE CONNECTOR UserNotifications WITH TYPE EMAIL
>     ADD SMTP_CONFIG
>         WITH HOST "smtp.office365.com"
>         WITH PORT '587'
>         WITH USERNAME "noreply@company.com"
>         WITH PASSWORD "secure-password"
>         WITH USE_TLS "true"
>     ADD EVENT userNotify
>         WITH SOURCE_TOPIC "users/+/notifications"
>         WITH TEMPLATE_PATH "/templates/user_notification.html"
>         WITH SUBJECT "Hello {value.json.username}"
>         WITH RECIPIENT "{value.json.email}"
> ```

> [tab] Report with images
>
> Embed images (a logo, a chart) directly in the email:
>
> ```lot wrap  theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> DEFINE CONNECTOR ReportEmail WITH TYPE EMAIL
>     ADD SMTP_CONFIG
>         WITH HOST "smtp.company.com"
>         WITH PORT '587'
>         WITH USERNAME "reports@company.com"
>         WITH PASSWORD "password"
>         WITH USE_TLS "true"
>     ADD EVENT sendReport
>         WITH SOURCE_TOPIC "reports/daily"
>         WITH TEMPLATE_PATH "/templates/daily_report.html"
>         WITH SUBJECT "Daily Report - {value.json.date}"
>         WITH RECIPIENT "management@company.com"
>         WITH EMBED_RESOURCES
>             ADD "/images/logo.png"
>             ADD "/images/chart.png"
> ```

> [!NOTE]
>
> For Gmail, use an [App Password](https://support.google.com/accounts/answer/185833) instead of your regular password. Enable 2FA on your Google account first.

***

## SMTP Configuration

The `SMTP_CONFIG` block tells the connector which mail server to send through and how to authenticate.

> [accordion] Server Settings
>
> **HOST** `string` *required*
>
> SMTP server address (e.g., `smtp.gmail.com`, `smtp.office365.com`).
>
> **PORT** `integer`
>
> SMTP port. Defaults to `587`. The connector secures the connection with STARTTLS, so use `587` (or `25`). Port `465`, which expects TLS from the first byte, isn't supported.
>
> **USE\_TLS** `boolean`
>
> Upgrade the connection with STARTTLS. Defaults to `true`.

> [accordion] Authentication
>
> **USERNAME** `string` *required*
>
> Account used to sign in to the SMTP server. It's also the sender (`From`) address.
>
> **PASSWORD** `string` *required*
>
> Email password or app-specific password.

***

## Event Configuration

Each `ADD EVENT` block defines a trigger topic and the content of the email it sends.

> [accordion] Trigger & Routing
>
> **SOURCE\_TOPIC** `string`
>
> MQTT topic to trigger email sending.
>
> **DESTINATION\_TOPIC** `string`
>
> MQTT topic that receives a confirmation after each email is sent. See [Confirming Delivery](#confirming-delivery).

> [accordion] Email Content
>
> **TEMPLATE\_PATH** `string`
>
> Path to the HTML template file on the machine (or container) that runs the broker. Use an absolute path. If the file can't be found, the email is still sent, with the raw message payload as its body.
>
> **SUBJECT** `string`
>
> Email subject line (supports placeholders).
>
> **RECIPIENT** `string`
>
> Email recipient address (supports placeholders). Required: if it resolves to an empty value, the email isn't sent.

### Template Placeholders

Subjects, recipients, and templates support placeholders that are filled in from the triggering message:

| Placeholder | Description |
| - | - |
| `{value}` | Full JSON payload as string |
| `{value.json.field}` | Single field from JSON |
| `{value.json.nested.field}` | Nested field access |

***

## Template Files

`TEMPLATE_PATH` points at a file the broker reads from its own file system. It is not uploaded with your LoT code, and it isn't read from the computer where you write the connector.

1. Save the template as an `.html` file on the broker host, for example `/opt/coreflux/templates/critical_alert.html`.
2. If the broker runs in Docker, mount the folder into the container and use the path as seen inside the container.
3. Set `TEMPLATE_PATH` to that full path.

If the path is wrong, nothing fails: the email arrives with the raw payload (for example `{"alert_type":"overheat"}`) as its body. That is the quickest sign that the broker can't see your template.

***

## Confirming Delivery

When an event has a `DESTINATION_TOPIC`, the connector publishes a JSON confirmation there after each email is handed to the SMTP server:

```json wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
{
  "success": true,
  "eventName": "criticalNotify",
  "to": "ops-team@company.com",
  "subject": "CRITICAL: overheat",
  "timestamp": "2026-10-26T10:15:02.120Z"
}
```

Wildcards in `DESTINATION_TOPIC` are filled from the matching levels of `SOURCE_TOPIC`, as with other connectors.

Nothing is published to `DESTINATION_TOPIC` when a send fails. Failures are recorded in the broker log (`Failed to execute event '<event>' in route '<connector>': <reason>`) and in the connector status topic, `$SYS/Coreflux/Routes/<connector_name>/status`. See [Connector Status Monitoring](https://docs.coreflux.org/latest/lot-language/routes/overview#connector-status-monitoring).

***

## Troubleshooting

> [accordion] Email Not Sending
>
> * Publish a test message to the exact `SOURCE_TOPIC`, with a payload that fills every placeholder in `SUBJECT` and `RECIPIENT`
> * Subscribe to `$SYS/Coreflux/Routes/<connector_name>/status` and watch `errors.total` and `messages.failed` while you send the test
> * Check the broker log for `Failed to execute event` and read the reason that follows
> * If the reason is `Event '<name>' has no RECIPIENT`, the recipient placeholder resolved to nothing. Check the field name in `{value.json.field}` against the payload
> * Verify SMTP credentials are correct. For Gmail, use an App Password
> * Use port `587` with `USE_TLS "true"`. Port `465` isn't supported
> * Check the firewall allows outbound SMTP connections from the broker host
> * If `DESTINATION_TOPIC` received a confirmation but nothing arrived, check the recipient's spam folder and the sending account's outbox

> [accordion] Email Arrives Without the Template
>
> * The body shows the raw payload when the broker can't find the file at `TEMPLATE_PATH`
> * Use the full path on the broker host, not on your own computer
> * In Docker, use the path inside the container and make sure the folder is mounted
> * See [Template Files](#template-files)

> [accordion] Email Authentication Failed
>
> * Double-check USERNAME and PASSWORD
> * Ensure 2FA is enabled if using app passwords
> * Some providers require enabling "less secure apps" access
> * Check for account lockouts due to failed attempts

***

## Next Steps

> [card] [LoT Actions](https://docs.coreflux.org/latest/lot-language/actions/overview)
>
> Publish the MQTT events that trigger notifications.

> [card] [Data Storage Connectors](https://docs.coreflux.org/latest/connectors/data-storage/overview)
>
> Store MQTT data in databases.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.