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 🙏

© 2024 – Pkg Stats / Ryan Hefner

onesecmail

v3.0.0

Published

Create and receive email in only 1 second.

Downloads

70

Readme

npm version npm downloads npm install size node version

Package using the 1secmail.com service.

Create and receive email in only 1 second.


Installation

Warning: This package is native ES modules and does not provide a CommonJS export. If your project uses CommonJS, you will have to convert to ESM or use the dynamic import() function.

Using npm:

npm install onesecmail

Using yarn:

yarn add onesecmail

Using pnpm:

pnpm add onesecmail

Usage

Once the package is installed, you can import the library using import:

import { OneSecMail, OneSecMailAPI } from "onesecmail";

Examples

OneSecMail

import { OneSecMail } from "onesecmail";

const mailbox = await OneSecMail("[email protected]");

const messages = await mailbox.getMessages();

for (const message of messages) {
  const fullMessage = await message.fetchFullMessage();
  console.log(fullMessage.serialize());
}

await mailbox.clearMessages();

OneSecMailAPI

import { OneSecMailAPI } from "onesecmail";

const options = {
  retry: 5,
  timeout: 3000,
};

const api = new OneSecMailAPI(options);

const [email] = await api.genRandomMailbox();

const [login, domain] = email.split("@");

const messages = await api.getMessages(login, domain);

for (const message of messages) {
  const fullMessage = await api.readMessage(login, domain, message.id);
  console.log(fullMessage);
}

API

Options

Options can be passed to the constructor and to each method.

// default options
const options: Partial<Options> = {
  retry: 2, // max retry failed requests
  timeout: 10_000, // milliseconds
};

OneSecMail

Create a mailbox

const mailbox = await OneSecMail();
const mailbox = await OneSecMail("[email protected]");
const mailbox = await OneSecMail(options);
const mailbox = await OneSecMail("[email protected]", options);

Returns an instance of OneSecMailbox.

OneSecMailbox.getMessages([options])

const messages = await mailbox.getMessages();
const messages = await mailbox.getMessages(options);

Returns an array of OneSecMailShortMessage instances.

OneSecMailbox.clearMessages([options])

await mailbox.clearMessages();
await mailbox.clearMessages(options);

OneSecMailbox.startPolling([intervalTime])

intervalTime must be at least 1000.

mailbox.startPolling(); // default intervalTime: 5000 milliseconds
mailbox.startPolling(30_000);

OneSecMailbox.stopPolling()

mailbox.stopPolling();

OneSecMailbox events

mailbox.on("newMessage", (message: OneSecMailShortMessage) => {
  console.log(message.serialize());
});
mailbox.on("error", (error: Error) => {
  console.error(error);
});

OneSecMailShortMessage.fetchFullMessage([options])

const fullMessage = await message.fetchFullMessage();
const fullMessage = await message.fetchFullMessage(options);

Returns an instance of OneSecMailMessage if the message still exists, otherwise throw an error.

OneSecMailMessage has an attachments field that contains an array of OneSecMailAttachment instances.

OneSecMailAttachment.download([options])

const file = await attachment.download();
const file = await attachment.download(options);

Returns a Buffer if the file still exists, otherwise throw an error.

OneSecMailAPI

This class is an exact reproduction of the official 1secmail.com API.

Create an instance

const api = new OneSecMailAPI();
const api = new OneSecMailAPI(options);

Instance methods

All methods return a Promise.

genRandomMailbox([count[, options]])

count must be between 1 and 500.

const emailAddresses = await api.genRandomMailbox(); // same to: genRandomMailbox(1)
const emailAddresses = await api.genRandomMailbox(5);
const emailAddresses = await api.genRandomMailbox(options); // same to: genRandomMailbox(1, options)
const emailAddresses = await api.genRandomMailbox(5, options);

Returns an array of generated email addresses.

getDomainList([options])

const domainList = await api.getDomainList();
const domainList = await api.getDomainList(options);

Returns an array of active domains.

getMessages(login, domain[, options])

const messages = await api.getMessages("demo", "1secmail.com");
const messages = await api.getMessages("demo", "1secmail.com", options);

Returns an array of ShortMessage (message with no body and attachments).

readMessage(login, domain, id[, options])

const message = await api.readMessage("demo", "1secmail.com", 639);
const message = await api.readMessage("demo", "1secmail.com", 639, options);

Returns a Message if the message exists, otherwise returns null.

download(login, domain, id, file[, options])

const file = await api.download("demo", "1secmail.com", 639, "iometer.pdf");
const file = await api.download("demo", "1secmail.com", 639, "iometer.pdf", options);

Returns a Buffer if the file exists, otherwise returns null.