Send Email
Send a templated email to the contact as a step in your automation.
The send email step sends a template email to the contact running through the automation. After adding a trigger, add this step, select a published template, and configure the subject and sender address. Over the API, add a send_email step to the steps array. See Using automations for the wider flow.
How it works
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": "044db673-fff6-420f-a566-f6aba05d60e7" }
}
}
],
"connections": [
{ "from": "start", "to": "welcome" }
]
});
console.log({ data, error });Template variables
Use the variables field to pass data into your template. Each value can be a dynamic reference or a static string.
| Type | Format | Description |
|---|---|---|
| Event data | { "var": "event.<field>" } | Resolves a field from the triggering event's payload. |
| Contact data | { "var": "contact.<field>" } | Resolves a field from the contact record. |
| Waited event data | { "var": "wait_events.<event>.<field>" } | Resolves a field from a preceding wait for event step's payload. |
| Static value | "<string>" | Passed as-is to the template. |
{
"key": "welcome",
"type": "send_email",
"config": {
"template": {
"id": "044db673-fff6-420f-a566-f6aba05d60e7",
"variables": {
"firstName": { "var": "event.firstName" },
"orderNumber": { "var": "event.orderId" },
"total": { "var": "event.amount" },
"company": { "var": "contact.properties.company" },
"feedback": { "var": "wait_events.feedback.received.response" },
"supportEmail": "help@example.com"
}
}
}
}Template variables must exist in your referenced template and the key names must match the template variable names exactly.
Configuration
config.templateobjectrequiredThe published template to send. Provide id and optionally variables.
config.template.idstringrequiredThe ID or alias of the template to send.
config.template.variablesobjectoptionalA key/value map of template variables. Each value is a static string or a variable reference ({ "var": "event.field" }) resolved from the event.*, contact.*, or wait_events.* namespaces.
config.fromstringoptionalThe sender email address. Overrides the template default when provided.
config.subjectstringoptionalThe email subject line. Overrides the template default when provided.
config.reply_tostringoptionalThe reply-to email address. Overrides the template default when provided.
{
"key": "welcome",
"type": "send_email",
"config": {
"template": {
"id": "062f8ef4-fbfa-44f1-b5e0-ff8e1e8ffa96",
"variables": {
"name": { "var": "event.firstName" }
}
},
"from": "hello@yourdomain.com",
"subject": "Welcome!",
"reply_to": "support@yourdomain.com"
}
}