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

mail-genie

v1.0.2

Published

A Node.js library for generating random emails, fetching domains, and parsing email content.

Readme

EmailTemp Usage Guide

This guide explains how to use the provided utility functions for fetching email domains, generating random emails, listing emails, and retrieving the email body.


Prerequisites

Before using the utility, ensure the following:

  • Node.js version 14 or higher is installed.
  • The required modules/functions are properly exported from ./index:
    • listEmails: Fetches the list of emails associated with an email address.
    • getEmailBody: Retrieves the content of an email by its inboxid.
    • getDomains: Retrieves a list of available email domains.
    • randomEmail: Generates a random email address using a specified domain.

Setup

  1. Ensure all required functions are implemented and exported in ./index.js.

  2. Install any necessary dependencies (if applicable):

    npm install
  3. Save the following example code in a file (e.g., example.js) and run it using Node.js.


Code Example

Here is a complete example of how to use the utility functions:

const { listEmails, getEmailBody, getDomains, randomEmail } = require('mail-genie');

(async () => {
    try {
        // Step 1: Get all available domains
        const allDomain = await getDomains();
        console.log("Available Domains:", allDomain);

        // Step 2: Select a random domain from the list
        const randomIndex = Math.floor(Math.random() * allDomain.length);
        const randomDomain = allDomain[randomIndex];
        console.log("Randomly Selected Domain:", randomDomain);

        // Step 3: Generate a random email using the selected domain
        const email = randomEmail(randomDomain);
        console.log("Generated Random Email:", email);

        // Step 4: Fetch the list of emails for the generated email address
        const listEmail = await listEmails(email.email);
        console.log("List of Emails:", listEmail);

        // Step 5: Fetch the body of the first email in the inbox
        if (listEmail.length > 0) {
            const bodyEmail = await getEmailBody(email.email, listEmail[0].inboxid);
            console.log("Email Body:", bodyEmail);
        } else {
            console.log("No emails found for this address.");
        }
    } catch (error) {
        console.error("An error occurred:", error.message);
    }
})();

Explanation

Step 1: Get All Available Domains

  • Use the getDomains function to retrieve a list of available email domains.
  • Example output:
    ["example.com", "test.com", "demo.com"]

Step 2: Select a Random Domain

  • Randomly select one domain from the retrieved list using Math.random().

Step 3: Generate a Random Email

  • Use the randomEmail function, passing the selected domain as a parameter.
  • Example output:
    { email: "[email protected]" }

Step 4: List Emails

  • Use the listEmails function, passing the generated email address to retrieve the list of emails associated with it.
  • Example output:
    [
      { inboxid: 123, subject: "Welcome!" },
      { inboxid: 124, subject: "Your Invoice" }
    ]

Step 5: Get Email Body

  • Use the getEmailBody function, passing the email address and the inboxid of the first email in the list to retrieve the email's content.
  • Example output:
    "Welcome to our service! We're glad to have you."

Error Handling

  • No Domains Available: If getDomains returns an empty array, the program will not proceed and should handle this with an error message.

  • No Emails Found: If listEmails returns an empty array, it will log "No emails found for this address.".

  • Invalid Parameters: Ensure randomEmail, listEmails, and getEmailBody are called with valid arguments.


Expected Output

Example Output:

Available Domains: ["example.com", "test.com", "demo.com"]
Randomly Selected Domain: test.com
Generated Random Email: { email: "[email protected]" }
List of Emails: [ { inboxid: 123, subject: "Welcome!" }, { inboxid: 124, subject: "Your Invoice" } ]
Email Body: "Welcome to our service! We're glad to have you."

Run the Example

To execute the example:

node example.js

License

This code is free to use and modify for your projects. No specific license is applied.