Automations
Automate emails with custom events.
Automations allow you to create email steps based on custom events from your application.
You can use automations for use cases like:
- Welcome emails
- Drip campaigns
- Payment recovery
- Abandoned cart
- Trial expiration
Automations support {{{MAILBLASTR_UNSUBSCRIBE_URL}}} for compliance with non-transactional product and marketing messaging.
How it works
To start executing an automation, you need to:
- 1Create Automation
Outline the sequence of steps to be executed.
- 2Add Trigger
Define the event name that will trigger the automation.
- 3Define Steps
Configure the steps to be executed.
- 4Send an Event
Trigger the automation by sending an event from your application.
- 5Monitor Runs
Track and debug your automation executions using runs.
1. Create an automation
The Automations page in the dashboard shows all existing automations. You can search by name and filter by status (All Statuses, Enabled, or Disabled) to quickly find the automation you need. Click Create automation to start a new automation.
An automation is either enabled or disabled. New automations start out disabled; only enabled automations create runs when a matching event is received.
Over the API, you can create an entire automation flow with a single request (status is optional and defaults to disabled):
name— the name of the automation.domain— required: the sending domain this automation belongs to (one of your domains). Only events sent with the samedomaintrigger it.status— the status of the automation (enabledordisabled).steps— the steps that compose the automation graph.connections— the connections between steps in the automation graph.
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.automations.create({
"name": "Welcome series",
"domain": "yourdomain.com",
"steps": [
{
"key": "start",
"type": "trigger",
"config": { "event_name": "user.created" }
},
{
"key": "welcome",
"type": "send_email",
"config": {
"template": { "id": "34a080c9-b17d-4187-ad80-5af20266e535" }
}
}
],
"connections": [
{ "from": "start", "to": "welcome" }
]
});
console.log({ data, error });The trigger is defined as the first item in the steps array with type: "trigger". domain ties the automation to one of your sending domains — only events sent with that domain trigger it, so running several products on one account can never cross-fire automations. For more help creating an automation via the API, see the Create Automation API reference.
status: "enabled" requires at least one step besides the trigger.2. Define steps
There are several step types you can add to your automation:
| Step type | Description |
|---|---|
| Condition | Branches the workflow based on rules. |
| A/B split | Randomly splits contacts between two branches by a percentage (deterministic per contact). Add a step with type: "split" and config.percent — branch A rides the True edge, branch B the False edge. |
| Delay | Pauses execution for a specified duration. |
| Wait for Event | Pauses execution until a specific event is received. |
| Send Email | Sends an email using a template. |
| Contact Update | Updates a contact's fields. |
| Contact Delete | Deletes the contact. |
| Add to Segment | Adds the contact to a segment. |
3. Send an event
Trigger the automation by sending an event from your application. domain names the sending domain the event belongs to — only that domain's automations fire. Identify the contact with a contact_id or an email.
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.events.send({
"event": "user.created",
"domain": "yourdomain.com",
"contact_id": "7f2e4a3b-dfbc-4e9a-8b2c-5f3a1d6e7c8b",
"payload": {
"plan": "pro"
}
});
console.log({ data, error });import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.events.send({
"event": "user.created",
"domain": "yourdomain.com",
"email": "user@example.com",
"payload": {
"plan": "pro"
}
});
console.log({ data, error });View the Send Event API reference for more details.
4. Monitor runs
After sending events, track your automation executions through runs. Each time an event triggers an automation, a run is created to track the execution.
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.automations.runs('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd');
console.log({ data, error });You can filter runs by status (running, completed, failed, cancelled, skipped). Learn how to:
- View run statuses and execution details
- Filter runs by status
- Debug failed runs with step-level error information
- Stop automations when needed
See the Runs documentation and the List Automation Runs API reference for more details.