# SMTP (/docs/adapters/smtp)



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 [#configure]

```ts
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 [#options]

| Option              | Type                             | Required | Notes                                     |
| ------------------- | -------------------------------- | -------- | ----------------------------------------- |
| `host`              | `string`                         | Yes      | SMTP host.                                |
| `port`              | `number`                         | No       | Common values are `587`, `465`, and `25`. |
| `secure`            | `boolean`                        | No       | Use TLS from the start of the connection. |
| `auth`              | `{ user: string; pass: string }` | No       | SMTP credentials.                         |
| `defaults`          | `{ replyTo?: string }`           | No       | Default reply-to header.                  |
| `tls`               | `Record<string, unknown>`        | No       | TLS options.                              |
| `requireTLS`        | `boolean`                        | No       | Require STARTTLS.                         |
| `allowInsecureAuth` | `boolean`                        | No       | Opt in to SMTP AUTH without TLS.          |
| `name`              | `string`                         | No       | Defaults to `smtp`.                       |
| `heloName`          | `string`                         | No       | EHLO name sent to the server.             |
| `timeoutMs`         | `number`                         | No       | Socket timeout.                           |

## Multiple SMTP routes [#multiple-smtp-routes]

Rename adapters when you have multiple SMTP routes.

```ts
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 [#cli]

```bash
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"
```
