Skip to content

feat(email): add MailKite as an alternative email provider - #2576

Open
bucabay wants to merge 1 commit into
boxyhq:mainfrom
bucabay:feat/mailkite-email-provider
Open

bucabay wants to merge 1 commit into
boxyhq:mainfrom
bucabay:feat/mailkite-email-provider

Conversation

@bucabay

@bucabay bucabay commented Aug 6, 2026

Copy link
Copy Markdown

What this adds

An alternative email provider alongside SMTP: when MAIL_PROVIDER=mailkite, sendEmail() sends through the MailKite API instead of an SMTP server. It reuses the exact nodemailer-based path the kit already uses for SMTP, so every existing sender (sendMagicLink, sendVerificationEmail, sendPasswordResetEmail, sendTeamInviteEmail, sendWelcomeEmail) works unchanged — no call-site changes.

MailKite is a developer email platform (inbound parsing via webhooks + transactional send). Some users prefer an API key over standing up an SMTP server, especially for magic-link / verification mail where deliverability matters and an API gives per-message tracking out of the box.

How to configure

.env.example:

# default — unchanged behavior
MAIL_PROVIDER=smtp

# switch to MailKite
MAIL_PROVIDER=mailkite
MAILKITE_API_KEY=mk_live_...        # https://mailkite.dev
# MAILKITE_BASE_URL=https://api.mailkite.dev   # optional override

SMTP_FROM is reused as the default from for both providers, so nothing else changes for existing users.

Backward compatibility

  • MAIL_PROVIDER defaults to smtp → the transporter, the if (!SMTP_HOST) return dev guard, and all send behaviour are byte-for-byte unchanged when unset.
  • When MAIL_PROVIDER=mailkite but no key is set (e.g. local dev), sendEmail no-ops, mirroring the existing "no SMTP host" behaviour, so the app still boots.

How I tested it

Locally against a fresh clone of main:

npx prisma generate
npm run check-types   # tsc --noEmit → 0 errors
npx eslint lib/email/sendEmail.ts lib/email/sendEmail.test.ts lib/env.ts   # clean
npx prettier --check <the changed files>   # clean
npx jest lib/email/sendEmail.test.ts        # 5/5 passing

lib/email/sendEmail.test.ts is the repo's first unit test; it covers provider selection (MailKite with/without key, custom base URL, SMTP default with/without host) by mocking nodemailer and the transport, so it asserts wiring without network. Jest already runs in CI (npm run test in .github/workflows/main.yml), so these will execute on this PR.

Note on package-lock.json: I intentionally did not commit it — my local npm (v11) dedupes the tree differently and would produce a ~2000-line churn unrelated to this change. Your CI runs npm install (not npm ci), which will add the new entry cleanly. Happy to regenerate it if you'd prefer a committed lockfile.

Disclosure

I work on MailKite, so I have an obvious interest in seeing it supported here — but the goal is a genuinely useful, maintained provider that fits the kit's existing patterns, not a drive-by. If a second mail provider isn't something you want to carry, no worries at all. If it is, I'm happy to maintain the integration (track nodemailer/Wasp/Next updates, keep tests green) and adjust the implementation to match whatever shape you'd prefer.

Closes nothing — opening for discussion; happy to refactor.

Add a `MAIL_PROVIDER` switch (default `smtp`, behavior unchanged) that
routes `sendEmail` through the MailKite API via the
`nodemailer-mailkite-transport` package when set to `mailkite`. It reuses
the same nodemailer-based path the kit already uses for SMTP, so every
existing sender (magic link, verification, password reset, team invite,
welcome) works unchanged.

- lib/env.ts: add `mailProvider` + `mailkite.{apiKey,baseUrl}` config
- lib/email/sendEmail.ts: select transport by provider; keep the
  no-op-when-unconfigured dev guard for both providers
- .env.example: document MAIL_PROVIDER / MAILKITE_API_KEY / MAILKITE_BASE_URL
- lib/email/sendEmail.test.ts: unit tests for provider selection
- package.json: add nodemailer-mailkite-transport (peer nodemailer >=6)
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the BoxyHQ Team on Vercel.

A member of the Team first needs to authorize it.

@bucabay

bucabay commented Aug 20, 2026

Copy link
Copy Markdown
Author

👋 Gentle bump on this — it's been ~2 weeks and is still mergeable. The only outstanding check is the Vercel fork-deploy authorization (needs a BoxHQ team member). Happy to rebase, address any review feedback, or adjust the docs table if that helps get it in.

This branch has not been deployed

No deployments
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