# SMTP

- Page: https://bytesms.com/docs/smtp (markdown: https://bytesms.com/docs/smtp.md)
- API base URL: https://api.bytesms.com/api (public resources under /api/v1)
- Auth: `Authorization: Bearer tp_live_…` — an API key from Dashboard → API Keys; keep it server-side (e.g. `BYTESMS_API_KEY`)
- All docs in one file: https://bytesms.com/llms-full.txt · OpenAPI 3.1: https://bytesms.com/openapi.json

Send email through the Bytesms SMTP gateway (smtp.bytesms.com, ports 465/587) with your API key as the password.

Anything that can send over SMTP — frameworks, CMSs, legacy apps — can send through Bytesms. SMTP messages go through the same pipeline as `POST /v1/emails`: the same verified-domain rules, quotas, suppression list, events, webhooks and logs.

## Connection settings

| Setting | Value |
| --- | --- |
| Host | `smtp.bytesms.com` |
| Port (implicit TLS) | `465` or `2465` |
| Port (STARTTLS) | `587` or `2587` |
| Username | `bytesms` |
| Password | An API key (`tp_live_…`) |
| Authentication | PLAIN or LOGIN |

Encryption is mandatory: on the STARTTLS ports, `AUTH` before `STARTTLS` is refused, and `MAIL FROM`without authentication is refused. The API key's permission and domain scope apply, so a domain-scoped `sending_access` key is a good fit for SMTP. Your settings are also shown in **Dashboard → Settings → SMTP**.

## Examples

**Node.js (nodemailer)**

```
import nodemailer from "nodemailer";

const transporter = nodemailer.createTransport({
  host: "smtp.bytesms.com",
  port: 465,
  secure: true, // implicit TLS
  auth: { user: "bytesms", pass: process.env.BYTESMS_API_KEY },
});

const info = await transporter.sendMail({
  from: "Acme <hello@example.com>",
  to: "customer@example.com",
  subject: "Hello over SMTP",
  html: "<p>It works!</p>",
});
console.log(info.response); // "250 OK: queued as <email id>"
```

**Python (smtplib)**

```
import os
import smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg["From"] = "Acme <hello@example.com>"
msg["To"] = "customer@example.com"
msg["Subject"] = "Hello over SMTP"
msg.set_content("It works!")
msg.add_alternative("<p>It works!</p>", subtype="html")

with smtplib.SMTP("smtp.bytesms.com", 587) as smtp:
    smtp.starttls()
    smtp.login("bytesms", os.environ["BYTESMS_API_KEY"])
    smtp.send_message(msg)
```

**swaks**

```
swaks --server smtp.bytesms.com:465 --tls-on-connect \
  --auth LOGIN --auth-user bytesms --auth-password "$BYTESMS_API_KEY" \
  --from hello@example.com --to customer@example.com \
  --header "Subject: Hello over SMTP" --body "It works!"
```

## How the message is read

- Recipients come from the SMTP envelope (`RCPT TO`). Those listed in the `To` header become `to`, those in `Cc` become `cc`, every other envelope recipient is `bcc`. At least one recipient must appear in `To`; at most 50 recipients per message.
- `From` and a non-empty `Subject` header are required; `From` must be on a verified domain. `Reply-To` is kept.
- The message needs a text or HTML body. Other custom headers are not passed through.
- Maximum message size: 10 MB.

> **Warning: Attachments are not supported**
>
> Messages with attachments are rejected with `554 5.6.1`. Link to files instead.

## SMTP replies

A successful `DATA` is answered with `250 OK: queued as <email id>`. Errors map to SMTP codes:

| Reply | Cause | Retry? |
| --- | --- | --- |
| `535 5.7.8` | Wrong username or API key; suspended key. | No |
| `421 4.7.0` | Too many failed logins from your IP (10 per 15 minutes). | Later |
| `451 4.7.1` | Request rate limit exceeded. | Yes |
| `452 4.5.3` | Daily quota or warm-up limit reached. | Tomorrow |
| `552 5.3.4` | Monthly quota, overage cap or spend limit reached; message too large. | No — change plan/limits |
| `553 5.7.1` | From domain not verified, or not allowed for this key. | No |
| `550 5.7.1` | Workspace sending paused, under review or suspended; other policy blocks. | No |
| `550 5.6.0` | Invalid message (missing From/Subject/body, no To recipient, …). | No |
| `554 5.6.1` | Attachments. | No |
| `451 4.3.0` | Temporary server error. | Yes |

Prefer the [REST API](https://bytesms.com/docs/emails)when you need tags, templates, scheduling or idempotency — SMTP doesn't support them.
