Feat: Add generic SMTP support for transactional emails
Problem
Self-hosted Cap deployments are currently locked into Resend as the only email provider. The relevant code path is in packages/database/emails/config.ts, where sendEmail() is wired directly to the Resend SDK with no abstraction.
For self-hosters, this creates real friction:
- We're forced to add yet another third-party SaaS account just for transactional emails, even when we already operate our own SMTP infrastructure (e.g. Postal, Plunk, Listmonk, AWS SES, or a basic mail relay)
- It contradicts the spirit of self-hosting — moving data ownership away from cloud services
- Without Resend configured, magic links and team invites only appear in container logs (
sendVerificationRequestfallback), which makes onboarding teammates impractical - The current
accept-inviteflow effectively requires email delivery to work end-to-end
Suggested Solution
Add a generic SMTP provider as a first-class alternative. Detection could be as simple as: if SMTP_HOST is set, use SMTP via nodemailer; otherwise fall back to Resend (or logs).
SMTP_HOST=mail.example.com
SMTP_PORT=587
SMTP_USER=...
SMTP_PASSWORD=...
[email protected]
SMTP_SECURE=false # or true for implicit TLS
The React Email rendering pipeline stays untouched — only the transport layer changes. nodemailer is the de-facto standard in the Node ecosystem for this and integrates cleanly with @react-email/render.
Why this matters
Cap is a fantastic open-source alternative to Loom, and the self-hosting story is a big part of its appeal. SMTP support would close one of the last gaps that currently force users into specific external SaaS providers — which is exactly the lock-in self-hosters try to avoid.
Good news: nodemailer is already a dependency in packages/database/package.json, so you won't need to add it.
The code you'll want to modify is in packages/database/emails/config.ts. The sendEmail() function currently checks for RESEND_API_KEY and returns early if missing. The detection logic you proposed (check for SMTP_HOST, use nodemailer, else fall back to Resend) fits cleanly here since React Email's render() gives you HTML that nodemailer can send directly.
For the new env vars (SMTP_HOST, SMTP_PORT, etc.), add them to packages/env/server.ts with Zod validation. The existing RESEND_* vars on lines 29-31 show the pattern.
A few call sites to be aware of:
packages/database/auth/auth-options.ts- OTP verification emails (lines 73-103 have the console fallback when Resend isn't configured)apps/web/actions/organization/send-invites.ts- team invite emailsapps/web/lib/Notification.ts- first-view notification emailsapps/web/app/api/email/new-comment/route.ts- comment notification emails
Related: #689 has a comment from @grpace requesting this same capability for self-hosters using Postal.
Thanks for the breakdown! Really helpful to have the call sites laid out. Glad to see #689 is asking for the same. Will keep an eye on this issue and #689... happy to test once a maintainer or community PR lands.
One small open question: should the SMTP path also handle the marketing email branch in sendEmail(), or skip those entirely on self-hosted (since that's a Cap Cloud-only flow anyway)?
PR #1900 implements this: a small pluggable EmailProvider abstraction so self-hosters can route transactional emails through any SMTP server (Postfix, internal relay, Brevo/Postmark via SMTP, etc.). Opt-in via EMAIL_PROVIDER=smtp, fully backward compatible (existing Resend setups keep working unchanged). The PR is now out of draft and ready for review.
Any updates on merging this?
For anyone following: #1775 and #1900 both implement this. I am a self-hoster with a working SMTP setup and can help E2E-test Resend + SMTP. Checking with the Cap team which PR they want to land so I don't open a third competing one.
+1 for this feature. Would be amazing to have other emails sending features as well.
Thanks! SMTP support is still something we'd take for self-hosters, a PR against current main that covers the newer sendEmail options would be welcome.
Hi @richiemcilroy, I'd like to take this against current main. Plan: a provider abstraction in packages/database/emails/ that keeps sendEmail's { data, error } result for both Resend and SMTP. It carries attachments and idempotencyKey (SMTP maps attachments to nodemailer and ignores idempotency/scheduledAt with a warning), uses nodemailer ≥ 7.0.7 via bun, and documents EMAIL_PROVIDER/EMAIL_FROM/SMTP_* in self-hosting.mdx and both compose files, per your list on #1900. One question: for #3994's scheduled first-Cap email, should SMTP deployments send it immediately or skip it? @KingsleyChimezie, happy to coordinate if you've started.
Nice to see another implementation from Hao. I also had this but forgot to push it.
@richiemcilroy you have 2 options here, choose whichever works best for cap. Would just love to see this added