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

Message

The EmailMessage shape field by field — addresses, headers, attachments, tags vs metadata, and the exact validation rules.

EmailMessage is the one message shape every adapter accepts. This page documents each field and the validation that runs before any request; which adapter maps which field is the field support matrix.

Fields

PropType
fromEmailAddress

Sender address.

TypeEmailAddress
toEmailAddress | EmailAddress[]

One or more recipients.

TypeEmailAddress | EmailAddress[]
subjectstring

Message subject.

Typestring
html?string

HTML body. At least one of html or text is required.

Typestring
text?string

Plain-text body. At least one of html or text is required.

Typestring
cc?EmailAddress | EmailAddress[]

Carbon-copy recipients.

TypeEmailAddress | EmailAddress[]
bcc?EmailAddress | EmailAddress[]

Blind-carbon-copy recipients.

TypeEmailAddress | EmailAddress[]
replyTo?EmailAddress | EmailAddress[]

Reply-to addresses.

TypeEmailAddress | EmailAddress[]
headers?Record<string, string> | EmailHeader[]

Custom message headers, as an object or a list.

TypeRecord<string, string> | EmailHeader[]
attachments?EmailAttachment[]

Files to attach, from memory or disk.

TypeEmailAttachment[]
tags?EmailTag[]

Provider-side categorical labels.

TypeEmailTag[]
metadata?Record<string, string | number | boolean | null>

Provider-side key-value data attached to the send.

TypeRecord<string, string | number | boolean | null>
idempotencyKey?string

Stable send identity, used when send options set none.

Typestring

Addresses

EmailAddress is a plain string — including the Name <email> form — or an object with a display name:

Adapters convert between the forms as their APIs require, so mix them freely.

Headers

Headers take two equivalent shapes; use whichever your data already has:

Attachments

Every attachment needs content or path:

  • content attaches in-memory data. String content is treated as raw (contentEncoding: "raw") and Base64-encoded for providers that need it — set contentEncoding: "base64" when the string is already Base64 so it is not double-encoded.
  • path makes the SDK read a local file at send time.

For inline images, set contentId and reference it from the HTML body with cid:, plus disposition: "inline":

Tags vs metadata

Both attach data to a send on the provider side, but they are different provider concepts:

  • tags are { name, value } labels for categorizing sends — provider dashboards and analytics group by them. Some providers carry only each tag’s value, and Postmark and Mailtrap accept a single tag.
  • metadata is free-form key-value data (string | number | boolean | null values) the provider stores with the message and echoes in webhooks and events.

Support differs per provider — Resend has tags but no metadata, Iterable has metadata but no tags. Check the field support matrix before relying on either, especially for fallback routes.

Idempotency key

idempotencyKey gives the send a stable identity across retries. The send-options key wins when both are set; the message field is the fallback. Only Resend transmits it natively — see idempotency keys for per-adapter behavior.

Validation

send validates the message before any adapter runs and throws EmailValidationError (code validation_error) with one of these exact messages:

Rule Error message
from is required Email message requires a from address.
At least one to recipient Email message requires at least one recipient.
subject is required Email message requires a subject.
html or text is required Email message requires either html or text content.
Attachments need data Attachment "<filename>" requires content or path.

Adapters add a second fail-fast layer for fields their provider cannot represent:

That error fires before any request — fields are rejected, never silently dropped. The per-adapter availability of cc, bcc, replyTo, headers, attachments, tags, and metadata is the field support matrix.

Last updated on