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

Create an adapter

Write your first custom provider adapter.

An adapter connects Email SDK’s normalized EmailMessage to one provider API. It is the thing that actually sends.

A plugin can register that adapter for package-style reuse. It is the thing most community packages should ask users to install.

You are writing… It should do… Users mount it with…
Adapter Map EmailMessage into one provider request and response. adapters: [...]
Adapter plugin Register one adapter from a reusable package or shared module. plugins: [...]

Start with the plain adapter because it is easier to test. Wrap it as a plugin when the adapter should be reused across projects or published as a community package.

Adapter shape

Map the payload

Keep provider-specific mapping in a helper. That keeps the adapter easy to test.

Use the adapter directly

Direct adapter registration is useful inside one app, one monorepo, or tests.

Wrap it as an adapter plugin

Adapter plugins are best for community packages and shared internal packages. The plugin does not send by itself; it returns metadata and the adapter list Email SDK should register.

Consumers can now mount it with the same plugins array as other extensions:

If the package is public, follow Publish a community adapter after the adapter tests pass.

Handle unsupported fields

Do not silently drop fields your provider cannot send. Throw a clear error instead.

This is especially important for fallback routes. A backup adapter that drops attachments, tags, or reply-to values can make a send look successful while changing the email.

Test the adapter

If your adapter accepts injected fetch, document it. It makes tests easier and keeps users from reaching for global mocks.

Checklist

  • Use one stable adapter name.
  • Return provider, id or messageId, and raw.
  • Pass context.signal into provider requests.
  • Respect context.idempotencyKey when the provider supports it.
  • Throw on unsupported fields instead of dropping them.
  • Add tests for payload mapping and provider response mapping.
  • If publishing, export both {provider} and {provider}Plugin.
  • If publishing, declare @opencoredev/email-sdk as a peer dependency.

See Adapter contract for the exact type reference.

Last updated on