# Email & SMTP Notifications

> Configure optional pure-Go outbound SMTP email for team invitations, security alerts, and agent kill-switch notifications—with live verification and clean link-only fallback.

Outbound email in OvertCMS is **completely optional**.

- **Without SMTP configured**: OvertCMS works 100% normally. When you invite a teammate in **Team**, Admin generates a one-time invite link you can copy and share manually.
- **With SMTP configured and verified**: OvertCMS can automatically email team invitation links, security alerts (new MFA enrollment or session compromise), and emergency agent kill-switch alerts—controlled by organization-level toggles in Admin.

Everything uses Go's standard library (`net/smtp` + `crypto/tls`) with plain-text UTF-8 messages, RFC 5322 address validation, and CR/LF header-injection protection.

---

## Environment Variables

Add these variables to your `.env.local` or deployment environment and restart `overtcms`:

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_SMTP_HOST` | `--smtp-host` | `""` | SMTP server hostname (e.g., `smtp.resend.com`, `smtp.postmarkapp.com`, `smtp.gmail.com`). Leave empty to disable SMTP. |
| `OVERTCMS_SMTP_PORT` | `--smtp-port` | `587` | SMTP server port (`587` for STARTTLS, `465` for implicit TLS, `1025` for local Mailpit/Mailhog). |
| `OVERTCMS_SMTP_USERNAME` | `--smtp-username` | `""` | Optional SMTP username (required by most providers). |
| `OVERTCMS_SMTP_PASSWORD` | `--smtp-password` | `""` | Optional SMTP password or provider API key. Never returned by any API. |
| `OVERTCMS_SMTP_FROM` | `--smtp-from` | `""` | Sender address in RFC 5322 format (e.g., `OvertCMS <no-reply@yourdomain.com>`). **Required** when `OVERTCMS_SMTP_HOST` is set. |
| `OVERTCMS_SMTP_TLS_MODE` | `--smtp-tls-mode` | `auto` | TLS behavior: `auto` (implicit TLS on port `465`, STARTTLS otherwise), `starttls`, `tls`, or `none` (local dev catchers only). |
| `OVERTCMS_ADMIN_BASE_URL` | `--admin-base-url` | `""` | Base URL of your Admin UI (e.g., `https://cms.yourdomain.com`) used to build clickable `/accept-invite?token=...` links in invitation emails. |

### Example Configuration (Resend / Postmark / Mailgun)

```bash
OVERTCMS_SMTP_HOST=smtp.resend.com
OVERTCMS_SMTP_PORT=587
OVERTCMS_SMTP_USERNAME=resend
OVERTCMS_SMTP_PASSWORD=re_your_api_key
OVERTCMS_SMTP_FROM="OvertCMS <no-reply@yourdomain.com>"
OVERTCMS_SMTP_TLS_MODE=auto
OVERTCMS_ADMIN_BASE_URL=https://cms.yourdomain.com
```

---

## Live Verification Gate

OvertCMS will **not** attempt to send live emails until your SMTP connection passes a live verification check—preventing misconfigured credentials from silently breaking invitations.

1. Open **Settings → Storage & Infrastructure** in the Admin UI.
2. Find the **Email & SMTP** card.
3. Optionally enter your own email address to receive a test message, then click **Verify SMTP** (or **Verify & Send Test Email**).
4. Behind the scenes, this calls `POST /admin-api/v1/system/smtp/verify`, performs a real TCP/TLS/AUTH handshake (plus test delivery if an address was provided), and flips `smtp.verified` to `true`.

<Note>
  Even if SMTP is configured and verified, email delivery is **non-blocking and fail-safe**: creating an invitation always succeeds and returns the one-time invite link (`inviteToken`) plus `emailSent: true | false` so you are never locked out if an upstream mail provider has an outage.
</Note>

---

## Organization Notification Controls

Organization **Owners** can toggle exactly which automated emails OvertCMS sends under **Settings → Storage & Infrastructure → Email Notifications** (or via `PATCH /admin-api/v1/organization`):

| Toggle (`organization.notifications`) | Default | When It Sends |
| :--- | :---: | :--- |
| **`sendInvitations`** | `true` | Automatically emails a clickable `/accept-invite?token=...` link whenever a teammate is invited. |
| **`securityAlerts`** | `true` | Alerts affected users on critical account security events (such as MFA enrollment or refresh-token compromise). |
| **`agentKillSwitchAlerts`** | `true` | Alerts organization owners/admins when the site's **AI Agent Kill Switch** is paused or resumed. |
