Email SDK

Plugins

Built-in plugins and extension points for Email SDK.

Plugins are add-ons for an email client. They can register adapters, change a message before validation, record send activity, or expose a small typed helper on the client.

Plugins are how repeated send-pipeline behavior becomes reusable: defaults before validation, observability after attempts, capture in tests, and adapter registration for community routes. For a full production path, see Production send pipeline.

Most apps should start with the built-in plugins. If a behavior should be reused across apps, move it into a plugin.

Built-in plugins

PluginImportUse it when
Defaults@opencoredev/email-sdk/plugins/defaultsEvery send needs shared headers, tags, metadata, reply-to, or idempotency defaults.
Observability@opencoredev/email-sdk/plugins/observabilityYou want logs, metrics, or traces without leaking recipients or email body content.
Capture@opencoredev/email-sdk/plugins/captureTests need to inspect attempted sends, retries, responses, and errors.
import { createEmailClient } from "@opencoredev/email-sdk";
import { defaultsPlugin } from "@opencoredev/email-sdk/plugins/defaults";
import { observabilityPlugin } from "@opencoredev/email-sdk/plugins/observability";
import { resend } from "@opencoredev/email-sdk/resend";

const email = createEmailClient({
  adapters: [resend({ apiKey: process.env.RESEND_API_KEY! })],
  plugins: [
    defaultsPlugin({
      headers: { "X-App": "billing" },
      sendMetadata: { service: "billing" },
    }),
    observabilityPlugin({
      log(event) {
        console.log(event.type, event.provider);
      },
    }),
  ],
});

What plugins can do

CapabilityExample
Register adaptersA community provider package can add its own EmailProvider.
Change a messageDefaults can add headers before provider validation.
Observe sendsObservability can emit redacted success, retry, and error events.
Capture testsCapture can expose email.capture.events.
Add helpersA plugin can add a small typed property to the returned client.

What plugins cannot do

Email SDK plugins do not add databases, migrations, HTTP endpoints, route middleware, rate limits, or server/client plugin pairs. Those are framework-level features. Email SDK plugins stay focused on sending email.

Common plugin shapes

ShapeWhere to start
Shared defaultsUse the defaults plugin.
Redacted loggingUse the observability plugin.
Test captureUse the capture plugin.
Custom providerFollow Create an adapter.
Reusable behaviorFollow Create your first plugin.
Community packageFollow Publish a community plugin.

Order

Plugin order is deterministic.

  1. Direct adapters register first.
  2. Plugins run in array order.
  3. Plugin adapters register in plugin order.
  4. Duplicate plugin IDs throw.
  5. Duplicate adapter names throw.
  6. beforeSend middleware runs before message validation.
  7. Plugin hooks run before user hooks.

Use a custom id when mounting more than one instance of the same plugin type. If the plugin extends the client, also give each instance a distinct extension key, such as capturePlugin({ id: "capture:audit", clientKey: "auditCapture" }).

Next

On this page