Email SDK
Adapters

SMTP

Configure generic SMTP for PurelyMail or a custom server.

The SMTP adapter is built in. It uses Node/Bun TCP and TLS sockets directly, so it does not need Nodemailer.

When auth is configured with secure: false, the adapter sends STARTTLS before authenticating. Set allowInsecureAuth: true only for a trusted local server that does not support TLS.

Configure

import { createEmailClient } from "email-sdk";
import { smtp } from "email-sdk/smtp";

const email = createEmailClient({
  adapters: [
    smtp({
      host: "smtp.purelymail.com",
      port: 587,
      secure: false,
      auth: {
        user: process.env.SMTP_USER!,
        pass: process.env.SMTP_PASS!,
      },
    }),
  ],
});

Options

OptionTypeRequiredNotes
hoststringYesSMTP host.
portnumberNoCommon values are 587, 465, and 25.
securebooleanNoUse TLS from the start of the connection.
auth{ user: string; pass: string }NoSMTP credentials.
defaults{ replyTo?: string }NoDefault reply-to header.
tlsRecord<string, unknown>NoTLS options.
requireTLSbooleanNoRequire STARTTLS.
allowInsecureAuthbooleanNoOpt in to SMTP AUTH without TLS.
namestringNoDefaults to smtp.
heloNamestringNoEHLO name sent to the server.
timeoutMsnumberNoSocket timeout.

Multiple SMTP routes

Rename adapters when you have multiple SMTP routes.

const email = createEmailClient({
  adapters: [
    smtp({ name: "purelymail", host: "smtp.purelymail.com" }),
    smtp({ name: "backup-smtp", host: "smtp.backup.example" }),
  ],
  defaultProvider: "purelymail",
  fallback: ["backup-smtp"],
});

CLI

email-sdk send \
  --adapter smtp \
  --host smtp.purelymail.com \
  --user hello@example.com \
  --pass "$SMTP_PASS" \
  --from "Acme <hello@example.com>" \
  --to user@example.com \
  --subject "SMTP test" \
  --text "It works"

On this page