Skip to content
You're viewing documentation for v0.6.1. It may be out of date.Go to latest
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Capture plugin

Record every send, retry, response, and error in tests — and assert on them through a typed client.capture store.

capturePlugin records send lifecycle events into a store and exposes it as client.capture — a typed property added through the plugin extension system. Pair it with the memory adapter to assert exactly what the SDK tried to do, without a network call.

email.capture is fully typed — capturePlugin() is an EmailPlugin<{ capture: EmailCaptureStore }>, so the extension flows into the client type with no casts.

What gets captured

Event type Fires when Extra fields
beforeSend The message enters the pipeline (once per send). message, send-option metadata
afterSend A provider returns a normalized response. provider, attempt, response
retry The SDK schedules another attempt on the same adapter. provider, attempt, nextAttempt, delayMs, error
error An adapter route fails after exhausting its retries. provider, attempt, error

Unlike the observability plugin, captured events hold the full, unredacted message — they are meant for test assertions, not production logs.

Reset between tests with email.capture.clear().

Options

PropType
id?string

Plugin id. Override when mounting multiple capture instances.

Typestring
Default"capture"
store?EmailCaptureStore

Bring your own store instead of an internal one.

TypeEmailCaptureStore
clientKey?string

Property name added to the client. The literal type flows into the client.

Typestring
Default"capture"

capturePlugin(store) is shorthand for capturePlugin({ store }).

Custom client key

clientKey renames the client property, and the type follows the literal you pass:

Multiple instances need distinct ids (duplicate plugin ids throw) and distinct clientKeys (a second plugin extending the client with an existing key throws).

Share a store

createEmailCaptureStore() creates a store you can hold a reference to directly — useful when the client is built inside a factory and your test only sees the store:

Capture vs memory adapter

They answer different questions: memoryProvider() replaces the network so nothing real sends, while capturePlugin() records what the pipeline did — including retries and errors the adapter alone cannot show. Most tests use both. See Test email behavior for the full testing setup.

Last updated on