Transactional Email Overview
Transactional emails are different from campaigns:- Sent immediately to individual recipients
- Use templates for consistent formatting
- Support custom data variables
- Can be sent to non-subscribers (external mode)
- Support file attachments
API Endpoint
The transactional email endpoint is defined incmd/handlers.go:195:
tx:send permission.
Message Format and Parameters
The transactional message structure is defined inmodels/messages.go:47-71.
Basic Request
Complete API Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
subscriber_emails | array | Conditional | List of recipient email addresses |
subscriber_ids | array | Conditional | List of subscriber IDs from database |
subscriber_mode | string | No | How to handle recipients: default, fallback, external |
template_id | integer | Yes | ID of template to use |
from_email | string | No | Sender email (defaults to system from_email) |
subject | string | No | Email subject (can override template subject) |
data | object | No | Custom template variables |
headers | array | No | Custom email headers |
content_type | string | No | Message content type |
messenger | string | No | Messenger to use (defaults to email) |
Subscriber Modes
Transactional emails support three subscriber modes (defined inmodels/messages.go:41-45):
Default Mode
- Looks up subscriber in database
- Fails if subscriber doesn’t exist
- Uses subscriber’s profile data in template
- Can use
subscriber_idsorsubscriber_emails
Fallback Mode
- Tries to find subscriber in database
- If not found, creates ephemeral subscriber for this email only
- Does NOT add to database
- Must use
subscriber_emails(IDs not allowed)
External Mode
- Always creates ephemeral subscriber
- Never checks database
- Perfect for sending to non-subscribers
- Must use
subscriber_emails(IDs not allowed)
cmd/tx.go:196-221.
Template Usage
Transactional emails use templates for consistent formatting.Creating a Transactional Template
- Go to Settings → Templates
- Create a new template with type “Transactional”
- Use template variables:
Available Template Variables
{{ .Subscriber.Email }}- Recipient email{{ .Subscriber.Name }}- Subscriber name{{ .Subscriber.UUID }}- Subscriber UUID{{ .Subscriber.Attribs }}- Custom subscriber attributes{{ .Tx.Data.* }}- Any custom data passed in request{{ .Tx.Subject }}- Email subject
models/messages.go:73-120.
Dynamic Subject Lines
You can use template variables in the subject:{{ are automatically compiled as templates (models/messages.go:94-101).
File Attachments
Send emails with file attachments using multipart form data.Example with cURL
Attachment Processing
Attachment handling is incmd/tx.go:20-59:
- Accepts multiple files in
filefield - Extracts filename and content type
- Encodes as base64 for email transmission
- Supports any file type
Attachment size is limited by your SMTP server configuration and
max_file_size setting.Custom Email Headers
Add custom headers to transactional emails:cmd/tx.go:154-162.
Use Cases
Password Reset Emails
Password Reset Emails
Order Confirmation
Order Confirmation
Welcome Email with Attachment
Welcome Email with Attachment
System Notifications
System Notifications
Rate Limiting
Transactional emails are subject to your SMTP server’s rate limits and listmonk’s configuration.Relevant Settings
Fromschema.sql:236-237:
Rate Limiting Behavior
The message manager (cmd/tx.go:164) pushes messages to a queue:
- Messages are processed by the manager’s worker pool
- Respects
message_ratethrottling - Failed messages are not automatically retried
- Check SMTP logs for delivery status
Error Handling
The API returns detailed error responses for troubleshooting.Common Errors
400 Bad Request - Invalid parametersHandling Errors in Code
Multiple Recipients
Send the same email to multiple recipients:cmd/tx.go:88-168):
- Each recipient gets an individual email
- Templates are rendered per-recipient
- If one fails, others still send
- Returns error if all recipients fail
Integration Examples
Best Practices
Use appropriate subscriber modes
defaultfor existing subscribersfallbackfor user accounts that may or may not be subscribersexternalfor guest users or system emails
Create dedicated templates
Separate templates for different email types (password resets, notifications, etc.)