Skip to content

Add email verification#1681

Merged
binwiederhier merged 10 commits into
mainfrom
email-verification
Mar 30, 2026
Merged

Add email verification#1681
binwiederhier merged 10 commits into
mainfrom
email-verification

Conversation

@binwiederhier
Copy link
Copy Markdown
Owner

@binwiederhier binwiederhier commented Mar 30, 2026

Verified email recipients

Adds email address verification for outgoing email notifications, gated behind a new smtp-sender-verify config flag (default false).

What it does

When smtp-sender-verify: true:

  • Anonymous users cannot send email notifications
  • Authenticated users must verify email addresses via a code sent to their inbox before those addresses can be used
  • Users can pass X-Email: yes (or true/1) to send to their first verified address
  • The "Email addresses" section appears in the web app account settings for adding/removing verified addresses

When smtp-sender-verify is unset or false, email sending works exactly as before — any user can send to any address. The feature is fully backwards compatible.

Changes

New mail package (mail/sender.go): SMTP email sending with SendRaw/Send methods, in-memory verification code storage with background expiry, and Close() for cleanup.

Database: New user_email table (SQLite + PostgreSQL migrations v6→v7) with Emails()/AddEmail()/RemoveEmail() on the user manager.

Server: Three new API endpoints (verify, add, delete email), convertEmailAddress() that enforces verification when the flag is on, ensureEmailsEnabled middleware, rate limiting verification emails against the user's email quota. smtpSender now delegates to mail.Sender.SendRaw() instead of duplicating SMTP auth logic.

Web app: Emails component (mirrors phone numbers), AddEmailDialog with verification code flow, EmailVerificationCodeInvalidError for specific error handling. Section only visible when enable_email_verify is true in the server config.

Config: smtp-sender-verify bool flag with CLI flag, env var (NTFY_SMTP_SENDER_VERIFY), server.yml docs, config generator toggle, and config reference table entry.

Tests: User manager tests for email CRUD + duplicate detection (SQLite + PostgreSQL), server tests covering verified address, bool value resolution, anonymous rejection, no-verified-emails, and backwards compatibility.

@binwiederhier binwiederhier changed the title WIP: Email verification Add email verification Mar 30, 2026
@binwiederhier binwiederhier merged commit 7ce5e8a into main Mar 30, 2026
2 checks passed
alexlebens pushed a commit to alexlebens/infrastructure that referenced this pull request Mar 31, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [binwiederhier/ntfy](https://github.com/binwiederhier/ntfy) | minor | `2.20.1` → `2.21.0` |
| [binwiederhier/ntfy](https://ntfy.sh/) ([source](https://github.com/binwiederhier/ntfy)) | minor | `v2.20.1` → `v2.21.0` |

---

### Release Notes

<details>
<summary>binwiederhier/ntfy (binwiederhier/ntfy)</summary>

### [`v2.21.0`](https://github.com/binwiederhier/ntfy/releases/tag/v2.21.0)

[Compare Source](binwiederhier/ntfy@v2.20.1...v2.21.0)

This release adds the ability to verify email addresses using the `smtp-sender-verify` flag. This is a change that is required because ntfy.sh was used to send unsolicited emails and the AWS SES account was suspended. Going forward, ntfy.sh won't be able to send emails unless the email address was verified ahead of time.

**Features:**

- Add verified email recipients feature with `smtp-sender-verify` config flag, allowing server admins to require email
  address verification before sending email notifications ([#&#8203;1681](binwiederhier/ntfy#1681))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkb2NrZXIiXX0=-->

Reviewed-on: https://gitea.alexlebens.dev/alexlebens/infrastructure/pulls/5300
Co-authored-by: Renovate Bot <renovate-bot@alexlebens.net>
Co-committed-by: Renovate Bot <renovate-bot@alexlebens.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant