Skip to content

Temp mail API for Node.js and TypeScript

temp-mail-plus-api is a small client for the tempmail.plus disposable email service. Generate a throwaway address, read its inbox, open a mail and delete it from your own code.

Unofficial community project. Not affiliated with or endorsed by Temp Mail Plus.

Read the getting started guide
inbox.mjs
import TempMail from "temp-mail-plus-api"; const { email } = TempMail.generateEmail();const tempMail = new TempMail(email); const inbox = await tempMail.fetchInbox();const [first] = inbox.mail_list ?? []; const mail = await tempMail.fetchMailById(first.mail_id);console.log(mail.text);

Example output

generateEmail()

k3v9x2ab@fexpost.com

username
k3v9x2ab
domain
fexpost.com

fetchInbox() count: 1

Example App no-reply@example.com

Your verification code

mail_id 32944585

fetchMailById(32944585)

from
Example App <no-reply@example.com>
to
k3v9x2ab@fexpost.com
text
Your verification code is 481902.
An illustration built from the response types in src/types.ts. This page sends nothing to tempmail.plus.

What you can call

The package exports one class and a list of domains. That is the whole surface, and every part of it is typed.

TempMail.generateEmail(username?, domain?)
Builds an address on your machine. You get a random 8 character username and a random domain unless you pass your own. No request is sent.
new TempMail(email, { timeout })
Binds a client to one address. The timeout is optional and defaults to 10 seconds.
fetchInbox()
Lists the mails waiting in the inbox. Each entry has the sender, the subject, the time and a mail_id.
fetchMailById(mail_id)
Returns one mail in full: text and html bodies, headers such as from and to, and the name, size and type of each attachment.
deleteMailById(mail_id)
Deletes one mail from the inbox.
setEmail(email)
Points the same client at a different address.
See every return shape in the API reference

A failed request is a return value

The three request methods never reject. When a request fails they resolve to { success: false, error }, where error is the message of the failure. On success you get the service's JSON with success: true added. Only the constructor and setEmail throw, and only for an address without an @.

Checking the result
const inbox = await tempMail.fetchInbox();

if (!inbox.success) {
  // the message of the error that was caught
  console.warn(inbox.error);
  return;
}

for (const item of inbox.mail_list ?? []) {
  console.log(item.from_mail, item.subject);
}
fetchInbox(), example output
{
  "error": null,
  "count": 1,
  "first_id": 32944585,
  "last_id": 32944585,
  "limit": 10,
  "mail_list": [
    {
      "attachment_count": 0,
      "first_attachment_name": "",
      "from_mail": "no-reply@example.com",
      "from_name": "Example App",
      "is_new": true,
      "mail_id": 32944585,
      "subject": "Your verification code",
      "time": "2026-01-01T00:00:00Z"
    }
  ],
  "more": false,
  "result": true,
  "success": true
}

Receive a signup email in a test

A disposable email API is handy when a test has to prove that a real message went out: a signup confirmation, a password reset or a one-time code. Generate an address, hand it to the app under test, then poll the inbox until the mail shows up. The library has no built-in wait, so the loop is yours to write. It is short.

Polling for a mail
async function waitForMail(tempMail, subject, tries = 15) {
  for (let i = 0; i < tries; i++) {
    const inbox = await tempMail.fetchInbox();
    const hit = (inbox.mail_list ?? []).find((m) => m.subject.includes(subject));
    if (hit) return tempMail.fetchMailById(hit.mail_id);
    await new Promise((r) => setTimeout(r, 2000));
  }
  throw new Error("No mail arrived");
}
Read the email testing guide

Nine domains to pick from

generateEmail() picks one of these at random. Pass a domain as the second argument to choose it yourself. The list is exported as TEMP_MAIL_DOMAINS and is hard-coded in the package, so it only changes with a new release.

  • @mailto.plus
  • @fexpost.com
  • @fexbox.org
  • @mailbox.in.ua
  • @rover.info
  • @chitthi.in
  • @fextemp.com
  • @any.pink
  • @merepost.com

Know what you are depending on

This client talks to the same web API that the tempmail.plus site uses. Temp Mail Plus does not publish or support it, and this project is not affiliated with them. If the service changes its endpoints or blocks scripted requests, calls will start returning success: false until the package catches up. Inboxes are not protected by a login, so treat anything sent to them as public.

Read the FAQ and limits