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 🙏

© 2026 – Pkg Stats / Ryan Hefner

smtp2go-nodejs

v1.0.0

Published

NodeJS Library for interacting with the SMTP2GO API

Readme

SMTP2GO Node API Wrapper

A library for sending email and accessing the SMTP2GO API from Node.js, browsers, and Web Workers.

Installation

npm i smtp2go-nodejs

Node.js

The package supports both ESM and CommonJS.

ESM

import SMTP2GOApi from "smtp2go-nodejs";

CommonJS

const { default: SMTP2GOApi } = require("smtp2go-nodejs");

Send an email

import SMTP2GOApi from "smtp2go-nodejs";
import { fileURLToPath } from "url";
import { dirname, resolve } from "path";

const __dirname = dirname(fileURLToPath(import.meta.url));
const api = SMTP2GOApi(process.env.APIKEY);

const mail = api.mail()
  .to({ email: "[email protected]", name: "Recipient" })
  .from({ email: "[email protected]", name: "Sender" })
  .subject("Hello!")
  .html("<h1>Hello World</h1>")
  .text("Hello World");

const result = await api.client().consume(mail);
console.log(result);

Attachments and inline images

const mail = api.mail()
  .to({ email: "[email protected]" })
  .from({ email: "[email protected]" })
  .subject("Check this out")
  .html('<h1>Hello</h1><img src="cid:my-image" />')
  .attach(resolve(__dirname, "./report.pdf"))
  .inline("my-image", resolve(__dirname, "./image.jpg"));

await api.client().consume(mail);

Multiple attachments can be passed as an array:

mail.attach([
  resolve(__dirname, "./file1.pdf"),
  resolve(__dirname, "./file2.pdf"),
]);

CC, BCC, and custom headers

const mail = api.mail()
  .to({ email: "[email protected]" })
  .cc({ email: "[email protected]" })
  .bcc([{ email: "[email protected]" }, { email: "[email protected]" }])
  .from({ email: "[email protected]" })
  .subject("Hello")
  .html("<p>Hello</p>")
  .headers({ header: "Reply-To", value: "[email protected]" });

await api.client().consume(mail);

Send using a template

const mail = api.mail()
  .to({ email: "[email protected]", name: "Recipient" })
  .from({ email: "[email protected]", name: "Sender" })
  .subject("Welcome!")
  .template(
    "your-template-id",
    new Map([
      ["username", "Steve"],
      ["action_url", "https://example.com/confirm"],
    ])
  );

await api.client().consume(mail);

Error handling

import SMTP2GOApi, { SMTP2GOError } from "smtp2go-nodejs";

try {
  const result = await api.client().consume(mail);
  console.log(result);
} catch (err) {
  if (err instanceof SMTP2GOError) {
    console.error(`API error ${err.status}:`, err.response);
  } else {
    throw err;
  }
}

Access other API endpoints

const service = api.service("stats/email_bounces", new Map([["days", "7"]]));
const result = await api.client().consume(service);

Browser / Web Worker

The package ships a separate browser build that uses the Web File API instead of Node's fs module. Bundlers (Vite, webpack, etc.) will resolve to it automatically via the browser field in package.json.

Web Worker

// worker.js
import SMTP2GOApi from "smtp2go-nodejs";

self.onmessage = async (event) => {
  const { apiKey, to, from, subject, html, file } = event.data;

  const api = SMTP2GOApi(apiKey);

  try {
    const mail = api.mail()
      .to(to)
      .from(from)
      .subject(subject)
      .html(html);

    // file is a File object transferred from the main thread
    if (file) {
      mail.attach(file);
    }

    const result = await api.client().consume(mail);
    self.postMessage({ success: true, result });
  } catch (err) {
    self.postMessage({ success: false, error: err.message });
  }
};
// main.js — spawning the worker and passing a File from a form input
const worker = new Worker(new URL("./worker.js", import.meta.url), {
  type: "module",
});

const fileInput = document.querySelector('input[type="file"]');

worker.postMessage({
  apiKey: "your-api-key",
  to: { email: "[email protected]" },
  from: { email: "[email protected]" },
  subject: "Hello from a worker",
  html: "<p>Sent from a Web Worker!</p>",
  file: fileInput.files[0],
});

worker.onmessage = ({ data }) => {
  if (data.success) {
    console.log("Sent:", data.result);
  } else {
    console.error("Failed:", data.error);
  }
};

Inline images in the browser

Pass a File object and a content ID (CID), then reference the CID in your HTML:

const mail = api.mail()
  .to({ email: "[email protected]" })
  .from({ email: "[email protected]" })
  .subject("Look at this")
  .html('<img src="cid:my-photo" />')
  .inline("my-photo", imageFileObject);

await api.client().consume(mail);