npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@xyz/email

v0.0.2

Published

Email provider abstraction for sending emails via multiple providers

Readme

@xyz/email

A unified library to send emails - Choose your own email provider.

Features

  • 🔌 Unified interface for multiple email providers
  • 📝 TypeScript support with full type definitions
  • 🔄 Easy to switch between providers without changing your code
  • 🚀 Works with Node.js, Bun, Deno, and Cloudflare Workers

Supported Providers

| Provider | Environment Variable | |----------|---------------------| | Nodemailer | MAIL_HOST, MAIL_PORT, MAIL_USER, MAIL_PASS | | Resend | RESEND_API_KEY | | Postmark | POSTMARK_SERVER_TOKEN | | Plunk | PLUNK_API_KEY | | Console | (none - logs to console) | | Custom | (implement your own) |

Installation

# npm
npm install @xyz/email

# pnpm
pnpm add @xyz/email

# yarn
yarn add @xyz/email

# bun
bun add @xyz/email

Environment Variables

Create a .env file with the appropriate variables for your chosen provider:

# Nodemailer (SMTP)
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USER=your-username
MAIL_PASS=your-password
[email protected]

# Resend
RESEND_API_KEY=re_xxxxxxxxxxxx

# Postmark
POSTMARK_SERVER_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

# Plunk
PLUNK_API_KEY=pk_xxxxxxxxxxxx

Usage

import { useEmail } from "@xyz/email";

// Choose your provider
const emailService = useEmail("resend");

// Send an email
await emailService.send({
  from: "[email protected]",
  to: "[email protected]",
  subject: "Hello!",
  text: "This is a plain text email.",
  html: "<h1>Hello!</h1><p>This is an HTML email.</p>",
});

Sending to Multiple Recipients

await useEmail("postmark").send({
  from: "[email protected]",
  to: ["[email protected]", "[email protected]"],
  subject: "Team Update",
  text: "Hello team!",
});

Switching Providers

const resend = useEmail("resend");
const postmark = useEmail("postmark");
const nodemailer = useEmail("nodemailer");
const plunk = useEmail("plunk");
const consoleLogger = useEmail("console"); // For development

API Reference

useEmail(provider: EmailProvider)

Creates an email service instance for the specified provider.

Parameters:

  • provider: One of "nodemailer" | "resend" | "postmark" | "plunk" | "console" | "custom"

Returns:

  • An email service instance with a send method

send(options: SendEmailParams)

Sends an email using the configured provider.

Parameters:

| Property | Type | Required | Description | |----------|------|----------|-------------| | from | string | ✅ | Sender email address | | to | string \| string[] | ✅ | Recipient email address(es) | | subject | string | ✅ | Email subject | | text | string | ❌ | Plain text content | | html | string | ❌ | HTML content |

Returns:

  • Promise<void>

Error Handling

try {
  await useEmail("resend").send({
    from: "[email protected]",
    to: "[email protected]",
    subject: "Hello",
    text: "Hello World",
  });
  console.log("Email sent successfully");
} catch (error) {
  console.error("Failed to send email:", error);
}

TypeScript Support

This package is written in TypeScript and provides type definitions out of the box.

import { useEmail, type SendEmailParams, type EmailProvider } from "@xyz/email";

const provider: EmailProvider = "resend";
const options: SendEmailParams = {
  from: "[email protected]",
  to: "[email protected]",
  subject: "Typed Email",
  text: "Hello!",
};

await useEmail(provider).send(options);

License

MIT