Bulk Mail JavaScript API

Everything the Bulk Mail extension adds to pb_hooks and page code, generated from the TypeScript declarations it ships (your app's types.d.ts has the same, so your editor knows them). For how to use it, see its docs; for Go, the Go API.

$bulkmail

Bulk mail campaigns. To react to its activity, use record hooks on its collections, e.g. onRecordAfterCreateSuccess(e => ..., "_bulkmail_suppressions").

$bulkmail.start()

$bulkmail.start(id: string, limit?: number): core.Record

Starts a campaign (at most limit sends; 0 = all); returns the campaign record.

Parameter Type
id string
limit number (optional)

Returns core.Record.

$bulkmail.pause()

$bulkmail.pause(id: string): core.Record

Stops sending (or a scheduled start) until resume; returns the campaign record.

Parameter Type
id string

Returns core.Record.

$bulkmail.resume()

$bulkmail.resume(id: string): core.Record

Continues a paused campaign; returns the campaign record.

Parameter Type
id string

Returns core.Record.

$bulkmail.cancel()

$bulkmail.cancel(id: string): core.Record

Stops a campaign for good: recipients still queued are marked skipped. Returns the campaign record.

Parameter Type
id string

Returns core.Record.

$bulkmail.test()

$bulkmail.test(id: string, to?: string): void

Sends one test message (to the given address, or the sender).

Parameter Type
id string
to string (optional)

$bulkmail.preview()

$bulkmail.preview(id: string, email?: string): bulkmail.Preview

Renders the campaign for one recipient.

Parameter Type
id string
email string (optional)

Returns bulkmail.Preview.

$bulkmail.count()

$bulkmail.count(audience: bulkmail.Audience): { count: number; suppressed: number; sample: string[] }

Counts an audience: total, how many are suppressed, and a few sample addresses.

Parameter Type
audience bulkmail.Audience

Returns { count: number; suppressed: number; sample: string[] }.

$bulkmail.suppress()

$bulkmail.suppress(email: string, reason?: string): core.Record

Adds the address to the suppression list (or updates its reason), so campaigns skip it. Fires no hooks: unsubscribe does.

Parameter Type
email string
reason string (optional)

Returns core.Record.

$bulkmail.unsuppress()

$bulkmail.unsuppress(email: string): void

Takes the address off the suppression list, so campaigns reach it again.

Parameter Type
email string

$bulkmail.isSuppressed()

$bulkmail.isSuppressed(email: string): boolean

Whether campaigns skip the address (it's on the suppression list).

Parameter Type
email string

Returns boolean.

$bulkmail.unsubscribe()

$bulkmail.unsubscribe(email: string, campaignId?: string): void

Suppresses the address and fires the unsubscribe hooks.

Parameter Type
email string
campaignId string (optional)

$bulkmail.unsubscribeURL()

$bulkmail.unsubscribeURL(email: string, campaignId?: string): string

The address's unsubscribe link, as every campaign message and its List-Unsubscribe header carry it.

Parameter Type
email string
campaignId string (optional)

Returns string.

$bulkmail.limits()

$bulkmail.limits(): { rate: number; daily: number; sentToday: number }

Sending limits: messages per second, per day, and sent today.

Returns { rate: number; daily: number; sentToday: number }.

Types

bulkmail.Audience

Who a campaign goes to: records of a collection, or a read-only SQL query.

type bulkmail.Audience = { collection: string; filter?: string; email_field?: string } | { sql: string };

bulkmail.Preview

Member Type
to string
from string
subject string
html string
text string
headers { [key: string]: string }