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.
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
fetchInbox() count: 1
Example App no-reply@example.com
Your verification code
mail_id 32944585
fetchMailById(32944585)
src/types.ts. This page sends nothing to tempmail.plus. 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?)new TempMail(email, { timeout })fetchInbox()fetchMailById(mail_id)deleteMailById(mail_id)setEmail(email) 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 @.
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);
}{
"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
}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.
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");
}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.
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.