mirror of
https://github.com/bitbaum/mail-kit.git
synced 2026-12-04 04:27:28 +01:00
v0.1.0
Born from the 2026-09-05 email sweep: ~12 bespoke implementations across
three provider styles, and a dead Brevo SMTP credential that silenced
evig+kivvi outbound mail for months unnoticed. One provider (Resend over
raw fetch, zero deps), one env contract (RESEND_API_KEY + RESEND_FROM),
one call shape: sendMail() that never throws and returns honest
{sent}|{error,status,retryable}; isMailConfigured() treating placeholder
keys and production sandbox senders as UNCONFIGURED; mailHealth() for
health endpoints; the <app>@fleetcrown.orangecat.ch sender convention
encoded once. 15 tests, golden pnpm CI, tag-driven publish, fleet
auto-merge.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn
@bitbaum/mail-kit
The fleet's one email layer. One provider (Resend), one env contract, one call shape, zero runtime dependencies.
Exists because the fleet grew ~12 bespoke email implementations across three provider styles, and a dead SMTP credential silenced two apps' outbound mail for months without anyone noticing. Uniformity is the fix.
Install
pnpm add @bitbaum/mail-kit
Use
import { sendMail, isMailConfigured, mailHealth, conventionalFrom } from "@bitbaum/mail-kit";
const result = await sendMail({
to: "person@example.ch",
subject: "Your invoice",
html: "<p>…</p>",
attachments: [{ filename: "invoice.pdf", content: pdfBuffer, contentType: "application/pdf" }],
});
if (!result.sent) {
// result.error, result.status?, result.retryable — sendMail NEVER throws.
logger.error("invoice email failed", result);
}
sendMailnever throws. A thrown email error inside a server action reaches nobody and destroys the form; a{ sent: false }you must look at is deliverable. Callers where delivery matters check.sent.isMailConfigured()— gate flows that depend on an email arriving (password reset, invoices). A placeholder key and a production sandbox sender (@resend.dev) count as unconfigured: both look configured and deliver to nobody.mailHealth()— key-validity + domain-status probe for/api/health. A passing probe does not prove delivery; only a real send does.options.idempotencyKey— pass from crons/queues so a retried job cannot double-send (Resend dedupes for 24h).
Env contract (the whole of it)
| Var | Meaning |
|---|---|
RESEND_API_KEY |
required to send |
RESEND_FROM |
sender — Name <addr> or bare address (optional if every call passes from) |
Fleet conventions
- The shared Resend account is on the free tier: 1 verified domain,
100 emails/day, 3,000/month. Hitting the daily cap surfaces as
{ sent: false, status: 429, retryable: true }. - Only
fleetcrown.orangecat.chis verified, so every app sends as<app>@fleetcrown.orangecat.ch—conventionalFrom("My App")builds it. - A daily canary on the box sends one real email and alerts Telegram when it fails — that, not this package, is what proves delivery keeps working.
What this is not
- Not a template engine — apps own their HTML.
- Not a queue —
retryabletells a caller whether a retry can help; scheduling one is the caller's decision. - Not for bulk — newsletters go through Listmonk.
Languages
TypeScript
99.2%
JavaScript
0.8%