A unified TypeScript hook for sending emails across multiple providers with a single interface. This package simplifies email sending operations by providing a consistent API regardless of the underlying email service provider.
Unified interface for multiple email providers
TypeScript support for enhanced developer experience
Works with Node.js, Bun, Deno, and Cloudflare Workers
Easy to switch between providers without changing your code
Supports modern email providers
Installation
You can install the package using your preferred package manager:
import { useEmail } from "use-email";
const emailService = useEmail("resend"); // Choose your provider
await emailService.send({
from: "sender@example.com",
to: "recipient@example.com",
subject: "Hello from use-email!",
text: "This is a test email sent using use-email package.",
});
const resendService = useEmail("resend");
const sendgridService = useEmail("sendgrid");
const postmarkService = useEmail("postmark");
const plunkService = useEmail("plunk");
const mailgunService = useEmail("mailgun");
The send method accepts an EmailOptions object with the following properties:
type EmailOptions = {
from: string;
to: string | string[];
subject: string;
html?: string;
text?: string;
};
The package throws errors for common issues such as missing API keys or required email fields. Always wrap your email sending code in a try-catch block:
try {
await emailService.send({
from: "sender@example.com",
to: "recipient@example.com",
subject: "Test Email",
text: "This is a test.",
});
console.log("Email sent successfully");
} catch (error) {
console.error("Failed to send email:", error);
}
This package is written in TypeScript and provides type definitions out of the box. You’ll get full IntelliSense and type checking when using it in a TypeScript project.
You can install the package using your preferred package manager:
# ✨ Auto-detect
npx nypm install use-email
# npm
npm install use-email
# yarn
yarn add use-email
# pnpm
pnpm install use-email
# bun
bun install use-email
Import:
undefinedESM (Node.js, Bun)
import {} from "pkg";
undefinedCommonJS (Legacy Node.js)
const {} = require("pkg");
undefinedCDN (Deno, Bun and Browsers)
import {} from "https://esm.sh/pkg";
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.