Skip to content
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Use provider-native features

Send a Postmark template, turn on SendGrid sandbox mode, or pick an SES configuration set per send without leaving the unified client.

The unified message covers what every provider shares. For features one provider has and others don’t, such as stored templates, tracking toggles, unsubscribe groups, or test modes, pass native on the send. Its keys are adapter names:

Postmark sends its stored welcome template. If the route falls back to Resend (when that happens), Resend sends the inline subject and text, because there’s no resend entry.

How routing treats native options

  • Each adapter that is tried receives only its own entry. Postmark options never reach Resend, and Resend options never reach Postmark.
  • An adapter with no entry sends exactly what it would send without native.
  • TypeScript infers the accepted keys from the adapters you passed to createEmailClient. An unknown key, a key for an adapter without native options (such as SMTP), or a field from another provider fails type checking.
  • That check needs a literal name for every adapter, the same as adapter and fallback route names. An unnamed smtp({ host }) written inside the adapters array gets the name type string, and the client then accepts any key. Pass name: "smtp" to keep the check.
  • The SDK doesn’t check the shape of native options at runtime. If a JavaScript caller passes the wrong shape, the provider’s own API returns the error. The only runtime checks are that the native map and each entry in it are built from plain objects and arrays (a class instance throws an EmailValidationError), and the two rules below for the body, fields, and headers escape hatches.
  • The SDK copies native when the send starts, and each adapter attempt gets its own copy of its entry. Changing an entry in middleware, a hook, or an adapter never changes your object, a retry, or the next adapter in the route.
  • Existing code annotated with EmailSendOptions<Name> keeps compiling. That type has no native field; to pass native options through your own helper, type the parameter as Parameters<typeof email.send>[1].

Templates

The message still needs a subject and html or text. When you set a native template, the adapter sends the template in place of the inline body, and the inline fields stay the content for other adapters in the route.

  • Resend: template: { id, variables, useTemplateSubject } replaces html and text. The message subject overrides the template’s default subject; set useTemplateSubject: true to keep the template’s.
  • Postmark: template: { id } or { alias }, plus model and inlineCss, sends to /email/withTemplate without Subject, HtmlBody, or TextBody.
  • SendGrid: templateId and dynamicTemplateData replace content. Dynamic templates take their subject from the template.
  • SES: template: { name } or { arn }, plus data, replaces Content.Simple. Headers and attachments are still sent.
  • Mailgun: template: { name, version, variables, renderText } replaces html and text. Mailgun still uses the message subject.
  • Brevo: templateId and params replace htmlContent and textContent. The message subject overrides the template’s subject; set useTemplateSubject: true to keep the template’s.
  • Loops: sends are always template-based. transactionalId overrides the adapter’s transactionalId for this send, and dataVariables adds data variables.

With sendPersonalized, a SendGrid dynamic template gets each recipient’s variables merged over dynamicTemplateData in that recipient’s personalization.

Other options by provider

Each adapter module exports its options type, for example PostmarkNativeOptions from @opencoredev/email-sdk/postmark.

  • Resend: topicId
  • Postmark: messageStream (overrides the adapter option), trackOpens, trackLinks, tag
  • SendGrid: asm (groupId, groupsToDisplay), ipPoolName, batchId, sandboxMode, tracking (clicks, opens, subscription)
  • SES: configurationSetName (overrides the adapter option), listManagement (contactListName, topicName), feedbackForwardingEmailAddress
  • Mailgun: tracking, trackingClicks, trackingOpens, testMode, requireTls, skipVerification, ipPool
  • Brevo: batchId
  • Loops: addToAudience

Sandbox and test modes (sendgrid.sandboxMode, mailgun.testMode) make the provider validate the request without delivering it. The send still resolves successfully. sendPersonalized builds its accepted list from the recipients it submitted, so with either mode on that list names people who were validated, not sent to. Telemetry doesn’t count these sends as provider volume. Both modes apply to that adapter alone: if the request fails and the route falls back, the next adapter sends for real, so leave fallback off for sandbox sends.

Fields the SDK doesn’t model

Resend, Postmark, SendGrid, SES, Brevo, and Loops accept two escape hatches in their entry, and so do Iterable, Mailchimp Transactional, MailerSend, MailPace, Mailtrap, Plunk, Scaleway, Sequenzy, SparkPost, Unosend, and ZeptoMail:

  • body is shallow-merged over the request body the adapter builds. Its top-level keys replace the SDK’s, so body.mail_settings replaces the whole object that sandboxMode would set.
  • headers adds HTTP headers to the provider API request. These are not email headers; use message.headers for those. Native headers only add names. The send throws an EmailValidationError before calling the provider when a native header names, in any letter case, a header the adapter sets itself: its credentials, Content-Type, or a name from the adapter’s own headers option. Resend also rejects Idempotency-Key on every send, even one without an idempotencyKey, because that option owns the header; pass idempotencyKey instead, which also gives each sendPersonalized recipient its own key. The same goes for Content-Length, Transfer-Encoding, and Host, which frame the request body. Mailgun’s Content-Type carries the multipart boundary that fetch generates, and SES signs each request with SigV4, so SES also rejects X-Amz-Date, X-Amz-Security-Token, and X-Amz-Content-Sha256.

Mailgun sends multipart form data, so its escape hatch is fields instead of body. Each field replaces the SDK’s value for that name, and an array value appends one field per item: fields: { "o:dkim": "no" }.

sendPersonalized rejects body and fields with an EmailValidationError before anything is sent. Either one can replace the recipients, such as SendGrid’s personalizations or Mailgun’s to, and the result’s accepted list would then name people the provider never received. Typed options and headers still work in personalized sends. To use body or fields, call send() for each recipient.

A send() with body or fields doesn’t count the message’s recipients as submitted in telemetry, since the passthrough may have replaced them.

SMTP, Cloudflare, Microsoft Graph, Helo, Sendheron, JetEmail, Primitive, Lettermint, and Lettr don’t take native options yet.

Batches

sendMany takes native both on the batch options and on each item. An item’s entry for an adapter replaces the batch entry for that adapter. Entries for other adapters still come from the batch.

The second item’s Postmark entry is { tag: "vip" } only, so it uses the adapter’s default stream.

Native options on a custom adapter

Declare the options type as the fourth type argument of EmailAdapter, and read it from context.native. Use a type alias, not an interface, so it fits the JSON-compatible constraint.

Fallbacks and retries

How a route moves from one adapter to the next.

Adapter contract

The full EmailAdapter type and context.

Last updated on