Emails
Send, fetch, list and cancel transactional emails (`publiq.emails`).
The emails resource covers a transactional message lifecycle: send (inline body or by template), track status, list history and cancel before dispatch.
Method reference
emails.send
emails.send(params, { idempotencyKey? }) → Promise<Email>Accepts and queues an email for delivery. The body can be inline (html/text) or come from a template (templateId or templateKey). Returns immediately with 202 — delivery is async; track it via emails.get or webhooks.
| Parameter | Type | Description |
|---|---|---|
fromRequired | string | Sender email. The domain must be verified. See Domains & DNS. |
toRequired | string | string[] | Recipient(s). Accepts a single email or a list (up to 50 recipients in the envelope). |
ccOptional | string | string[] | Carbon copy (Cc). One email or a list. |
bccOptional | string | string[] | Blind carbon copy (Bcc). One email or a list. |
subjectOptional | string | Subject (max 998 chars). Required when the body is not from a template that already has a subject. |
htmlOptional | string | Inline HTML body. |
textOptional | string | Inline plain-text body (fallback and better deliverability). |
templateIdOptional | string | A versioned template ID. Alternative to html/text. |
templateKeyOptional | string | Readable template key (e.g. welcome-email) — a friendly alternative to templateId. See Templates. |
variablesOptional | object | Interpolation variables ({ first_name: "Ana" } → {{ first_name }}). See Variables. |
tagsOptional | object | Free-form tags for search and reporting (e.g. { campaign: "q3" }). |
externalIdOptional | string | Your-side correlation (e.g. order id). |
idempotencyKeyOptional | string (opção) | Idempotency key (2nd argument, outside the body). If omitted, the SDK auto-generates one per call. Retries with the same key won't duplicate the email. See Errors & idempotency. |
Returns: The created email — { object: "email", id, status: "queued", ... }. Keep the id to query later.
const email = await publiq.emails.send({
from: 'you@yourdomain.com',
to: ['ana@example.com', 'bob@example.com'],
cc: 'boss@example.com',
templateKey: 'welcome-email',
variables: { first_name: 'Ana', plan: 'Pro' },
tags: { campaign: 'onboarding' },
});
console.log(email.id, email.status); // "em_...", "queued"html, text or a template (templateId/templateKey). None → 400 validation_error. A suppressed recipient never receives (per-recipient filter). See Suppressions.idempotencyKey (e.g. order-42-receipt) when the send originates from your own event — that way a retry on your side never duplicates the email.emails.get
emails.get(id) → Promise<Email>Fetch an email details by id: current status, recipients (to/cc/bcc), provider, tags and event timestamps (delivered, opened, etc.).
| Parameter | Type | Description |
|---|---|---|
idRequired | string | Email ID (returned by emails.send). |
Returns: The email with its status and event history. 404 if it does not exist in the organization.
const email = await publiq.emails.get('em_123');
console.log(email.status); // "delivered"emails.list
emails.list({ status?, limit?, after? }) → Promise<EmailList>List the organization emails, newest first, cursor-paginated. Filter by status to reconcile deliveries.
| Parameter | Type | Description |
|---|---|---|
statusOptional | string | Filter by status: queued, processing, delivered, bounced, failed, canceled. |
limitOptional | number | Items per page (default 20, max 100). |
afterOptional | string | Cursor: id of the last item on the previous page. |
Returns: List envelope { object: "list", data: Email[] }. Use the last item id as after on the next call.
const { data } = await publiq.emails.list({ status: 'delivered', limit: 50 });
// next page:
const next = await publiq.emails.list({ after: data[data.length - 1].id });id in after until data comes back empty. See Errors & pagination.emails.cancel
emails.cancel(id) → Promise<Email>Cancel an email still in the queue (queued), preventing dispatch. Useful for scheduled or mistakenly-triggered sends.
| Parameter | Type | Description |
|---|---|---|
idRequired | string | ID of the email to cancel. |
Returns: The email with status: "canceled". Returns 409 (conflict) if it already left the queue (processing/delivered).
await publiq.emails.cancel('em_123'); // only while queued409 as “too late”: catch the error and move on — the email was already dispatched. See Errors.Examples show Node, Python and PHP. In Python methods are snake_case (e.g. cancel_run, from_spec) and take a dict; in PHP they are camelCase and take an associative array. Body keys are always camelCase (templateKey, firstName, scheduledAt) — API responses come back in snake_case.