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 your first plugin

Build a reusable send policy plugin.

This guide builds a small policy plugin that requires each send to include a metadata value. The same shape works for tenant checks, route enforcement, audit defaults, or environment-specific guardrails.

What you will build

The plugin will:

  1. Accept a required metadata key.
  2. Run before provider validation.
  3. Block the send when the key is missing.
  4. Add a tiny typed helper to the returned client.

Create the plugin file

Use it

The returned client now has a typed email.requiredEmailMetadata property.

Block a send

That call throws before any adapter is called. beforeSend errors are not swallowed because policy plugins need to be able to stop unsafe sends.

Add tests

Plugin rules

  • Use a stable id.
  • Make IDs unique when mounting multiple instances.
  • Use beforeSend for behavior that can block a send.
  • Use afterSend, onError, and hooks for observability work.
  • Keep client extensions small and avoid names like send, adapter, or defaultAdapter.

For exact types, see Plugin API.

Last updated on