Skip to main content

Guides

Bulk sending

Pass an array to send() for bounded-concurrency bulk sends that never throw.


Pass an array to send() and each message becomes its own request, sent with bounded concurrency. The call never throws — you get one result per message.

const results = await send([
	{ to: 'a@example.com', body: '…' },
	{ to: 'b@example.com', body: '…' }
]);
const results = await send([
	{ to: 'a@example.com', body: '…' },
	{ to: 'b@example.com', body: '…' }
]);

Concurrency and results

On a provider instance you can tune concurrency (default 5). Each result tells you whether that message succeeded:

const results = await mail.send(messages, { concurrency: 10 });

const failed = results.filter((r) => !r.ok);
for (const r of failed) console.error(r.index, r.error.message);
const results = await mail.send(messages, { concurrency: 10 });

const failed = results.filter((r) => !r.ok);
for (const r of failed) console.error(r.index, r.error.message);

Because the call never throws, you handle failures by inspecting results rather than with try/catch. Each failed result carries the same normalised PostboiError on .error.

Hooks run once per message, so before.send, after.send, and on.error fire for each item in the array.