emailkit
v0.1.10
Published
Unified email API for multiple providers.
Maintainers
Readme
EmailKit
Unified email SDK with pluggable drivers (Mailgun, Resend, AIInbx) and optional Next.js helpers.
Install
npm i emailkitUsage
import { EmailKit, MailgunDriver } from "emailkit";
const emailkit = EmailKit({
emailDriver: MailgunDriver({ apiKey: process.env.MAILGUN_API_KEY! }),
hooks: {
onInboundEmail: async (event) => {
console.log("Received inbound email:", event);
},
onOutboundEmailOpened: async (event) => {
console.log("Email opened:", event);
},
},
});
await emailkit.sendEmail({
from: { email: "[email protected]", name: "Sender" },
to: { email: "[email protected]" },
subject: "Hello",
text: "Hello world",
});Webhooks (framework-agnostic)
const handle = emailkit.webhookRoute();
const res = await handle({ method, headers, body });Provider fetch helper
Call provider-specific endpoints while reusing the configured authentication and base URL:
const response = await emailkit.providerFetch("/v4/domains", {
method: "GET",
searchParams: { limit: 25 },
});
if (!response.ok) throw new Error("Provider API failed");
const domains = await response.json();The helper accepts any fetch options plus an optional searchParams object. Pass absolute URLs when the provider returns fully qualified links (for example, stored attachment URLs); the helper still injects auth headers.
Next.js adapter (optional)
import { createNextJsWebhookHandler } from "emailkit/nextjs";
export const POST = createNextJsWebhookHandler(emailkit.webhookRoute());