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

SMTP

Send over raw SMTP with the built-in TCP/TLS transport — no Nodemailer, no HTTP API.

The SMTP adapter speaks the SMTP protocol directly over Node/Bun TCP and TLS sockets — no Nodemailer, no HTTP, no dependency. Point it at PurelyMail, a self-hosted server, or any provider’s SMTP endpoint, and register it more than once under different names for multiple routes.

SMTP
SMTP@opencoredev/email-sdk/smtp
Provider docs

Configure

Get the host, port, TLS mode, and credentials from your SMTP provider.

PropType
hoststring

SMTP server hostname.

Typestring
port?number

SMTP server port.

Typenumber
Default465 when secure, else 587
secure?boolean

Connect with implicit TLS from the first byte (typically port 465).

Typeboolean
Defaultfalse
auth?{ user: string; pass: string; method?: "plain" | "login" }

SMTP credentials. method picks the AUTH mechanism; the default is "plain" (AUTH PLAIN), set "login" for AUTH LOGIN.

Type{ user: string; pass: string; method?: "plain" | "login" }
requireTLS?boolean

Force a STARTTLS upgrade even when no auth is configured.

Typeboolean
Defaultfalse
allowInsecureAuth?boolean

Permit AUTH over a plaintext connection. Only for trusted local servers.

Typeboolean
Defaultfalse
tls?tls.ConnectionOptions

Extra options merged into the TLS connection (e.g. ca, rejectUnauthorized).

Typetls.ConnectionOptions
defaults?{ replyTo?: string }

Default Reply-To header applied when a message has no replyTo.

Type{ replyTo?: string }
name?string

Adapter name override — register several SMTP servers side by side.

Typestring
Default"smtp"
heloName?string

Hostname announced in the EHLO command.

Typestring
Default"localhost"
timeoutMs?number

Timeout for the connection and each SMTP command.

Typenumber
Default15000

TLS and auth semantics

With secure: true the whole session is TLS. Otherwise the adapter connects in plaintext and upgrades with STARTTLS before authenticating whenever requireTLS is set or auth is present — credentials never travel unencrypted. Authenticating against a server that cannot do TLS requires an explicit allowInsecureAuth: true; without it the adapter throws instead of sending the password in the clear.

Send

SMTP maps cc, bcc, replyTo, and headers. When a message has both html and text, the adapter builds a multipart/alternative MIME body. The generated Message-ID header is <{idempotencyKey}@email-sdk.local> when the message has an idempotencyKey (a random UUID otherwise), and an explicit Message-ID in headers overrides it — set one yourself if you need a specific domain for threading or deduplication.

rejected is always empty — a refused recipient fails the SMTP conversation instead, and every transport error surfaces as a retryable EmailProviderError, so SMTP plays well with retries and fallbacks.

Multiple SMTP routes

name lets you register the adapter twice and use one route as the fallback for the other.

Verify from the CLI

doctor only checks SMTP_HOST; the other settings are optional.

Each flag falls back to its env var: --host/SMTP_HOST, --port/SMTP_PORT (default 587), --secure/SMTP_SECURE, --require-tls/SMTP_REQUIRE_TLS, --allow-insecure-auth/SMTP_ALLOW_INSECURE_AUTH, --user/SMTP_USER, --pass/SMTP_PASS. Drop --dry-run for one real send — the only check that proves the host, TLS mode, and credentials actually deliver.

Last updated on