Mail Suite docs
Send email from your application.
Base URL https://mailsuite.mercestack.com. Verify a domain, create a key, then send.
Authentication
Every request carries an API key as a bearer token. Create keys in the dashboard under API keys. A sending key can only send; a full key can also read emails back.
Authorization: Bearer msk_live_…
Send an email
POST /v1/email with a JSON body. from must be an address on a verified domain. to, cc and bcc take a string or an array (50 recipients in total). Provide html, text, or both; when only html is sent a text part is generated. Optional: replyTo, headers (X-* and List-Unsubscribe only), tags, scheduledAt (up to 30 days ahead). Send an Idempotency-Key header to make retries safe. Answers 202 with { id, status }.
POST /v1/email
{
"from": "Acme <receipts@acme.com>",
"to": ["ada@example.com"],
"subject": "Your receipt",
"html": "<p>Thanks — £24.00 paid.</p>",
"tags": { "order": "1042" }
}
202 { "data": { "id": "eml_…", "status": "queued" } }Send a batch
POST /v1/email/batch with { emails: [...] } — up to 100 messages. Every message is validated before any is accepted, so a mistake in one sends none; the error names it as emails[i].
POST /v1/email/batch
{ "emails": [ { …one email… }, { … } ] }
202 { "data": [ { "id": "eml_…" }, … ] }Retrieve an email
GET /v1/email/{id} with a full-access key returns the email, its status and its timeline of events.
GET /v1/email/eml_…
200 { "data": { "id": "eml_…", "status": "sent", "events": [ … ] } }Cancel a scheduled email
DELETE /v1/email/{id} cancels an email that is still scheduled. A cancelled email does not count against your allowance.
DELETE /v1/email/eml_…
200 { "data": { "id": "eml_…", "status": "cancelled" } }Webhooks
Add an endpoint under Webhooks and choose its events: email.sent, email.delivered, email.delayed, email.bounced, email.complained, email.failed. Each POST carries Mercestack-Signature: t=<unix>,v1=<hex>, where v1 is HMAC-SHA256 of "t.body" with your endpoint's secret. Reject requests whose signature does not match or whose t is old. Failed deliveries are retried over about eight hours.
const [t, v1] = header.split(",").map((p) => p.split("=")[1]);
const expected = createHmac("sha256", secret)
.update(`${t}.${rawBody}`).digest("hex");
if (!timingSafeEqual(Buffer.from(v1), Buffer.from(expected))) reject();Contacts
POST /v1/contacts adds or updates a contact by email: firstName, lastName, properties (any keys, used in templates as {{ key }}), unsubscribed, and topics as { topicId: true | false }. Contacts are your audience for broadcasts and automations.
POST /v1/contacts
{
"email": "ada@example.com",
"firstName": "Ada",
"properties": { "plan": "pro" }
}
200 { "data": { "id": "con_…", "created": true } }Events and automations
POST /v1/events records something that happened — name (like user.signed_up), email, and optional data. The person is added to your audience, and every automation that is on and waits for that event starts for them. Templates read the data as {{ data.key }}.
POST /v1/events
{
"name": "user.signed_up",
"email": "ada@example.com",
"data": { "plan": "pro" }
}
202 { "data": { "id": "evt_…", "automationsStarted": 1 } }Errors
Errors are { error: { code, message } }. 400 a malformed request · 401 a missing or revoked key · 402 the monthly allowance is used up · 403 the key or domain may not send this · 404 not found · 422 a recipient is suppressed · 429 slow down.
422 { "error": { "code": "unprocessable", "message": "ada@example.com is on the suppression list…" } }