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

Writing plugins

Create adapter, middleware, and community plugins.

Write a plugin when email behavior should be reused across clients, apps, or packages.

Start with one of these shapes:

Shape Use it for
Adapter plugin Package a provider as plugins: [providerPlugin()].
Middleware plugin Add defaults, policy, capture, or observability around sends.
Hook plugin Reuse existing EmailHooks callbacks.
Client extension Add a small typed helper to the returned client.

Adapter plugin

Adapter plugins are the best shape for community providers.

Application code stays clean:

Middleware plugin

Use beforeSend when the plugin needs to change or block a message.

beforeSend errors are not swallowed. Use it for policy.

Use afterSend and onError for observability work that should not block provider behavior.

Programmatic adapter registration

Use ctx.addAdapter when a plugin creates adapters dynamically.

Duplicate adapter names throw. If a factory both calls ctx.addAdapter(adapter) and returns the same adapter object, Email SDK registers it once.

Client extension

Use extendClient for tiny helpers or stores. Keep it boring.

Extension keys cannot collide with built-in client keys like send, sendBatch, adapter, or defaultAdapter.

Community adapter checklist

  • Use a stable plugin id and adapter name.
  • Keep credentials in plugin options.
  • Support context.signal for network requests.
  • Pass context.idempotencyKey when the provider supports idempotency.
  • Return normalized id, messageId, accepted, or rejected fields when available.
  • Put provider responses in raw when useful for debugging.
  • Map every supported EmailMessage field.
  • Reject unsupported fields before calling the provider.
  • Test payloads with injected fetch or a local test server.

Community packages can export both a plain provider factory and an adapter plugin. Use the plugin shape when you want the one-call setup path.

Last updated on