Skip to content
BuildBase

Email campaigns overview

Author campaigns in the console, send to an audience, and track delivery through the REST API.

Campaigns are authored in the BuildBase console: pick a template, pick an audience, send or schedule. The API is for driving and observing that pipeline from your backend, not for composing mail in code.

Note

There is no bb.email.send(). The BuildBase() server factory has no email namespace. To send one transactional message to one user, use bb.notification.send() - it renders the event's email template and respects the user's preferences. To send one email to any address from your backend, use the email API. Campaigns are for audience-scale sends.

// Send a campaign that was prepared in the console
const response = await fetch(
  `https://api.console.buildbase.app/api/emails/campaigns/${campaignId}/send`,
  {
    method: 'POST',
    headers: { Authorization: process.env.BUILDBASE_API_TOKEN! },
  }
);

Before you start

Before a campaign can send, you need a working sender (SMTP, Google, Mailgun or Amazon SES, under Messaging > Sender accounts; a Mailgun sender also needs a verified sending domain, while SMTP, Google and Amazon SES authenticate the domain at that provider), and a template with an unsubscribe link and your postal address (the unsubscribe and companyAddress merge tags, with the address set under merge tags). Anti-spam law in the US, Canada and the EU requires both in marketing email, and the send is refused (422 EMAIL_PRESEND_FAILED) until they are there.

The pipeline

  1. Template - the reusable body, with merge tags. See templates and merge tags.
  2. Sender - who it comes from, through a sender with an active account; a Mailgun sender also on a verified domain.
  3. Campaign - a template plus an audience plus a schedule.
  4. Drafts - one queued message per recipient, materialized from the campaign.
  5. Send - the queue delivers, and history records the outcome per recipient.

Drafts are the step that surprises people. A campaign does not send directly to an audience: it first expands into per-recipient drafts, and the send walks those. That is what makes partial retry possible.

Campaign endpoints

All require an Authorization header - see the admin API for the token format and list-query parameters.

MethodPathPurpose
GET/api/emails/campaignsList campaigns, paginated
GET/api/emails/campaigns/:idOne campaign
POST/api/emails/campaignsCreate
PATCH/api/emails/campaigns/:idUpdate
POST/api/emails/campaigns/:id/create-draftsExpand the audience into per-recipient drafts
POST/api/emails/campaigns/:id/sendSend the campaign
POST/api/emails/campaigns/:id/retry-failedRe-queue only the recipients that failed
DELETE/api/emails/campaigns/:idDelete
GET/api/emails/campaigns/:id/presend-checkWhat blocks the send, and what is only advice
POST/api/emails/campaigns/:id/scheduleSend at scheduledAt, checked now
POST/api/emails/campaigns/:id/unscheduleBack to draft
POST/api/emails/campaigns/:id/pauseHold what has not gone out
POST/api/emails/campaigns/:id/resumeRe-queue what was held
POST/api/emails/campaigns/:id/cancelDrop what has not gone out, for good
POST/api/emails/campaigns/:id/release-sampleSend to the rest now, after the health check
POST/api/emails/campaigns/:id/archivePublish or withdraw the web version
GET/api/emails/campaigns/:id/postmasterGmail's data for the days it went out

Scheduling, pausing, the first-send sample and the A/B subject test are described in Sending campaigns.

retry-failed re-queues failures without touching recipients who already received the message, so it is safe to call more than once after a partial delivery failure. It returns the counts it acted on:

{
  "message": "Retried 12 failed emails, 3 skipped",
  "retried": 12,
  "skipped": 3
}

Campaign status

A campaign is always in one of eight states, and the action endpoints are guarded by it:

StatusMeaning
draftEditable, not yet dispatched
scheduledWaiting for its scheduledAt; starts sending on its own
sendingDispatch in progress
pausedStopped mid-send by a person or the sending health check; resumable
cancelledStopped for good; recipients not reached yet are never sent
sentDispatch finished
failedDispatch failed
archivedRetired
EndpointAllowed fromRejected with
/create-draftsdraft only400 - Cannot create drafts for campaign in "X" state
/senddraft or failed400 - Cannot send campaign in "X" state
/scheduledraft, failed or scheduled (a new time replaces the old)409 - Only a draft, failed or scheduled campaign can be scheduled.
/unschedulescheduled only; it goes back to draft409 - Only a scheduled campaign can be unscheduled.
/pausesending, or sent while some of its messages still wait in the send queue409 - Only a campaign that is sending can be paused.
/resumepaused only; it goes back to sending409 - Only a paused campaign can be resumed.
/cancelsending or paused, or sent while some messages still wait409 - Only a campaign that is sending or paused can be cancelled.
/release-sampleA campaign holding the rest back after its first-send sample409 - The rest was not sent: <reason>.
/archiveAny state: it sets the web version (archive), not the status-

/send accepting failed is what makes a whole-campaign retry possible after a dispatch collapses. Use /retry-failed instead when the campaign partly succeeded - re-sending from failed state is coarser.

The two 400 rejections use the { error: true, message, path: "status" } shape; the 409 ones answer { success: false, message }.

Delivery history

Every send writes a history row per recipient with a status, and tracking records opens and clicks when the template includes the tracking pixel. Both are exposed as chart endpoints the console renders, and as ordinary list endpoints you can page through.

Delivery is asynchronous. /send returns { "message": "Campaign dispatch started" } as soon as the work is queued - that is not a delivery confirmation. Poll the history rows for per-recipient outcomes.

Recipients are resolved from the campaign's audience list and expanded in batches of 500, so a large list produces drafts progressively rather than in one pass.

In the console

Open Email history in the console (opens the console in a new tab)

In the left rail choose Messaging, then Email history: every message your organization sent, from campaigns, workflows, your app and sign-in, with totals and a chart. Filter by template narrows it to one template.

Email history under Messaging: the Email history menu item highlighted as step 1, Filter by template as step 2, the totals for the last 7 and 30 days, and Email volume

Press Details on a row for one message: its status, subject, sender, recipient, when it was sent, each open and click, and its body. The subject is shown as its reader got it, merge tags filled in, except that a sign-in code or a link reads [hidden]; a message sent before this was kept shows the template's subject. The body is shown as the template wrote it; each merge tag is filled in for its reader when the message goes out. Retry on a failed row sends it again, and Send now sends a scheduled one at once.

Email details: Sent, highlighted as step 3, the subject Cohort reports are here, From, To Jordan Kim, Send on, the opens and clicks table, and the body

Drafts lists mail made but not sent yet, such as a campaign's messages while it sends, with Send and archive on each row.

Email drafts: the Drafts menu item highlighted as step 4, Draft volume and Draft emails

Inside a non-production environment, Inbox keeps every message the platform sender sent, links and codes included (the inbox).

Open the Inbox in the console (opens the console in a new tab)

Switch to the environment, then choose Inbox, the first item under Email: it shows only there.

A Development environment's Inbox: the Inbox menu item highlighted as step 5, the note on who the BuildBase sender reaches, and Nothing sent yet

Unsubscribes

Two merge tags render opt-out links. Both resolve at send time to a page on your application URL - not the API - carrying a per-recipient token, so the link identifies the recipient without a login:

Merge tagResolves to
{{unsubscribe}}<your-app>/unsubscribe-email-group?token=…
{{manage-preference}}<your-app>/manage-email-preference?token=…

The preference center is backed by its own token-validated API under /api/manage-email-preference, which is what the page calls to read and update preferences. You do not call it directly.

Every audience campaign should carry at least one of these tags. The pre-send check refuses a campaign whose template has neither. Marketing mail, and any message sent under an unsubscribe group, also carries a List-Unsubscribe header. That is a hidden line at the top of the message that Gmail and Yahoo use to show their own Unsubscribe button. See Unsubscribes and opt-in.

Providers

BuildBase sends through a provider account you connect yourself: Google, Mailgun, Amazon SES, and custom SMTP. BuildBase has no mail account of its own to send your production mail for you. Domain verification runs through your own Mailgun account, so a verified sending domain requires connecting it, whichever provider delivers a given sender.

A development or staging environment with no sender of its own is the exception. Its mail goes through a platform sender, and only to your team's addresses and to pending invitees. Every subject carries the environment's name. Every message it sends is kept in the console's Inbox, links and codes included. Production never uses it.

Send one email from your backend

To send one email from your server, such as a receipt or a shipping notice, call the email API with an org API key. It runs the checks the console does: a working sender and the suppression list (addresses BuildBase will not send to). It does not count against your plan's monthly email quota, which counts marketing mail, but it has limits of its own: a daily number of API sends set by your plan, and 30 emails to one address per hour. Past either, it answers 429 with SEND_LIMIT_REACHED.

It also takes an Idempotency-Key header: a name you give this one send. If your server retries the request with the same key, the email still goes out only once.

curl -X POST https://api.console.buildbase.app/api/v1/server/emails/send \
  -H "Authorization: $BUILDBASE_API_TOKEN" \
  -H "Idempotency-Key: order-1234-shipped" \
  -H "Content-Type: application/json" \
  -d '{"to":{"email":"[email protected]"},"templateId":"TEMPLATE_ID","data":{"orderId":"1234"}}'

A new send answers 202 (accepted, not yet sent) with { id, status: "queued", replayed: false }. A retry with the same key answers 200 with the same id and replayed: true. The SDK wraps it as emails.send() on createServerClient from @buildbase/sdk/server, together with subscribers.upsert() and the rest of the subscriber calls. Requires @buildbase/sdk 1.0.0 or later. See Send transactional email for the parameters, the refusal codes and idempotency.

Next Steps