SMTP
Send over SMTP with a standards-compliant MIME transport. No HTTP API.
Capabilities
| Repeated headers | Idempotency | Scheduling | Personalized |
|---|---|---|---|
| Yes | message_id |
No | expanded |
These values come from the adapter’s exported capabilities declaration. The field support matrix covers normalized message fields.
The SMTP adapter uses Nodemailer for the SMTP protocol, TLS, authentication, MIME composition, transfer encoding, RFC-safe subject encoding, and attachments. 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.
Comparing SMTP with a provider’s HTTP API first? How to send email from Node.js and TypeScript shows both side by side. Sending through Resend’s SMTP server? Resend SMTP settings has the host, ports and TLS options.
Configure
Get the host, port, TLS mode, and credentials from your SMTP provider.
import { createEmailClient } from "@opencoredev/email-sdk";
import { smtp } from "@opencoredev/email-sdk/smtp";
export const email = createEmailClient({
adapters: [
smtp({
host: "smtp.purelymail.com",
port: 587,
auth: {
user: process.env.SMTP_USER!,
pass: process.env.SMTP_PASS!,
},
}),
],
});
hoststring
SMTP server hostname.
stringport?number
SMTP server port.
number465 when secure, else 587secure?boolean
Connect with implicit TLS from the first byte (typically port 465).
booleanfalseauth?{ 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.
{ user: string; pass: string; method?: "plain" | "login" }requireTLS?boolean
Force a STARTTLS upgrade even when no auth is configured.
booleanfalseallowInsecureAuth?boolean
Permit AUTH over a plaintext connection. Only for trusted local servers.
booleanfalsetls?tls.ConnectionOptions
Extra options merged into the TLS connection (e.g. ca, rejectUnauthorized).
tls.ConnectionOptionsdefaults?{ replyTo?: string }
Default Reply-To header applied when a message has no replyTo.
{ replyTo?: string }name?string
Adapter name override, for registering several SMTP servers side by side.
string"smtp"heloName?string
Hostname announced in the EHLO command.
string"localhost"timeoutMs?number
Timeout for the connection and each SMTP command.
number15000TLS 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, so credentials do not 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, headers, and attachments. Nodemailer builds the MIME tree, chooses safe transfer encodings, encodes non-ASCII subjects, and supports content or path attachments (including inline contentId attachments). 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 send options include an idempotencyKey, and a random UUID otherwise. An explicit Message-ID in headers overrides it; set one yourself if you need a specific domain for threading or deduplication.
const result = await email.send({
from: "Acme <alerts@acme.com>",
to: "ops@example.com",
cc: "oncall@example.com",
subject: "Disk usage above 90% on db-1",
text: "db-1 is at 92% disk usage.",
html: "<p><strong>db-1</strong> is at 92% disk usage.</p>",
headers: [{ name: "X-Alert-ID", value: "alert_481" }],
});
console.log(result.accepted); // every recipient the server accepted
console.log(result.id); // parsed from the server's "queued as ..." reply, else the idempotency key
rejected is always empty, because a refused recipient fails the SMTP conversation instead. Retryable transport failures surface as EmailAdapterError, 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.
export const email = createEmailClient({
adapters: [
smtp({
name: "purelymail",
host: "smtp.purelymail.com",
auth: { user: process.env.PURELYMAIL_USER!, pass: process.env.PURELYMAIL_PASS! },
}),
smtp({
name: "backup-smtp",
host: "smtp.backup.example",
auth: { user: process.env.BACKUP_SMTP_USER!, pass: process.env.BACKUP_SMTP_PASS! },
}),
],
defaultAdapter: "purelymail",
fallback: { adapters: ["backup-smtp"] },
});
Verify from the CLI
doctor only checks SMTP_HOST; the other settings are optional.
SMTP_HOST=smtp.purelymail.com npx --package @opencoredev/email-sdk email-sdk doctor --adapter smtp
export SMTP_PASS="..."
npx --package @opencoredev/email-sdk email-sdk send \
--adapter smtp \
--host smtp.purelymail.com \
--port 587 \
--require-tls \
--user hello@acme.com \
--from "Acme <hello@acme.com>" \
--to user@example.com \
--subject "SMTP smoke test" \
--text "It works" \
--dry-run
For a real send, 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. The boolean flags take an optional =true or =false that overrides the env var, and an env var enables its option only when set to true. With --user, the CLI authenticates only over TLS unless the opt-out is on (--allow-insecure-auth or SMTP_ALLOW_INSECURE_AUTH=true). Because each flag overrides its env var, --require-tls=false cancels SMTP_REQUIRE_TLS=true but never allows plaintext AUTH on its own. Drop --dry-run to test SMTP submission with the host, TLS mode, and credentials, then check the recipient’s inbox to confirm delivery.
To test locally without sending real email, point the adapter at Mailpit; see MailHog and Mailpit: test email locally in Node.js.
Frequently asked questions
Does Email SDK support SMTP?
Yes. Email SDK ships a SMTP adapter imported from @opencoredev/email-sdk/smtp. You keep your SMTP account and credentials; the SDK adds message validation, typed errors, and no-network test adapters around the same send() call used for every other provider.
Which message fields does the SMTP adapter support?
SMTP supports CC recipients, BCC recipients, Reply-To address, Custom headers, and Attachments. It does not support Tags, Metadata, and Scheduled sending (sendAt); Email SDK rejects a message that uses those fields before any request is made.
Can SMTP schedule email for later with Email SDK?
No. SMTP has no provider-side scheduling, so a message with sendAt fails validation. Store the job in your own queue and send when it is due.
Does the SMTP adapter support idempotent sends?
Partially. The SMTP adapter derives a stable Message-ID from the idempotency key, but the receiving server decides whether to deduplicate.