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

eml-generator

v1.0.0

Published

Generate EML (email) files from JSON data in Node.js and browsers

Readme

eml-generator

A lightweight TypeScript/JavaScript library for generating EML (RFC 5322) email files. Works in both Node.js and browser environments.

Features

  • Generate RFC 5322 compliant EML files
  • Support for plain text and HTML content
  • File attachments with Base64 encoding
  • Custom email headers
  • Works in Node.js and browsers
  • Full TypeScript support
  • Zero dependencies
  • Proper MIME handling

Installation

npm install eml-generator

Usage Modes

eml-generator offers three convenient ways to generate EML files:

  1. Programmatic API - Use in Node.js or browser applications
  2. Command Line Interface - Generate EML files from the terminal → Jump to CLI docs
  3. Web Interface - Create emails using our online demo

1. Programmatic API

Basic Example

import { eml } from 'eml-generator';

const emailContent = eml({
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Hello',
  text: 'This is a test email'
});

// In Node.js:
import { writeFileSync } from 'fs';
writeFileSync('email.eml', emailContent);

// In browser:
const blob = new Blob([emailContent], { type: 'message/rfc822' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'email.eml';
a.click();

For more advanced usage including attachments, HTML content, and custom headers, see the API Reference below.

2. Command Line Interface

Quickly generate EML files from your terminal:

# Basic usage
eml-generator -t "[email protected]" --text "Hello World" -o email.eml

# Multiple recipients and CC
eml-generator -t "[email protected],[email protected]" -c "[email protected]" --text "Hello"

# Using HTML and text content from files
eml-generator -t "[email protected]" --text-file message.txt --html-file message.html

For all available CLI options, see the CLI Reference below.

API Reference

eml(options: EmlOptions): string

EmlOptions

interface EmlOptions {
  headers?: Record<string, string | string[]>;
  subject?: string;
  from?: string | EmailAddress | EmailAddress[];
  to: string | EmailAddress | EmailAddress[];
  cc?: string | EmailAddress | EmailAddress[];
  text?: string;
  html?: string;
  attachments?: Attachment[];
}

interface EmailAddress {
  name?: string;
  email?: string;
}

interface Attachment {
  filename?: string;
  name?: string;
  contentType?: string;
  inline?: boolean;
  cid?: string;
  data: string | Buffer;
}

CLI Reference

The package includes a CLI tool for generating EML files directly from the command line:

# Basic usage
eml-generator -t "[email protected]" --text "Hello World" -o email.eml

# Multiple recipients and CC
eml-generator -t "[email protected],[email protected]" -c "[email protected]" --text "Hello"

# Using HTML and text content from files
eml-generator -t "[email protected]" --text-file message.txt --html-file message.html

# Adding attachments
eml-generator -t "[email protected]" -a "document.pdf,image.jpg"

# Custom headers
eml-generator -t "[email protected]" --text "Test" --header "X-Custom: Value"

CLI Options

Required:

  • -t, --to <emails> Recipient email(s), comma separated

Optional:

  • -f, --from <email> Sender email
  • -s, --subject <text> Email subject
  • -c, --cc <emails> CC email(s), comma separated
  • --text <content> Plain text content
  • --html <content> HTML content
  • --text-file <path> Plain text content from file
  • --html-file <path> HTML content from file
  • -a, --attach <files> File attachments, comma separated
  • -o, --output <file> Output EML file (default: output.eml)
  • --header <key:value> Custom header (can be used multiple times)
  • -h, --help Show help message
  • -v, --version Show version number

Development

Setup

  1. Clone the repository:
git clone https://github.com/username/eml-generator.git
cd eml-generator
  1. Install dependencies:
npm install
  1. Run tests:
npm test
  1. Build the library:
npm run build

Scripts

  • npm test - Run the test suite
  • npm run build - Build for production (outputs CJS and ESM)
  • npm run typecheck - Run TypeScript type checking

Local Development

To run the demo page locally:

  1. Build the library: npm run build
  2. Serve the docs directory (you can use any static file server)
  3. Open docs/index.html in your browser

Continuous Integration

The project uses GitHub Actions for automated testing and deployment:

  • Tests run on Node.js 16.x, 18.x, and 20.x
  • TypeScript type checking is performed
  • Build verification ensures the library can be compiled
  • GitHub Pages demo is automatically deployed on pushes to main

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.