opex-tempmail.so
v1.0.0
Published
A Node.js library to interact with a temporary email service API - tempmail.so
Readme
Temp Mail Client
A simple Node.js ESM library to programmatically create temporary email addresses and receive emails, based on the API used by temp-mail.org.
Disclaimer: This library is based on reverse-engineering the public API of a third-party service. It may break at any time if the service changes its API. Please use it responsibly and ethically.
Features
- Generate a new temporary email address.
- Fetch all emails from the inbox.
- Read the full HTML body of a specific email.
- Delete a specific email.
- Delete the entire inbox to get a new address.
- Session management with cookies.
Installation
npm install axios axios-cookiejar-support tough-cookieUsage
Here is a basic example of how to use the library.
import { createTempMailClient } from './src/index.js';
async function run() {
try {
// Initialize the client and get the first email address
const client = await createTempMailClient();
console.log(`Your temporary email is: ${client.address}`);
// Wait for an email to arrive
console.log('Waiting for an email...');
const firstMail = await client.waitForFirstMail({ timeout: 60000 }); // 60-second timeout
console.log('--- New Email Received ---');
console.log(`From: ${firstMail.from}`);
console.log(`Subject: ${firstMail.subject}`);
// Read the email's content
const body = await client.getMailBody(firstMail.id);
console.log('--- Email Body ---');
console.log(body.substring(0, 200) + '...'); // Print first 200 chars
// Get a new email address
console.log('\nGetting a new email address...');
const newAddress = await client.deleteInbox();
console.log(`Your new temporary email is: ${newAddress}`);
} catch (error) {
console.error(error.message);
}
}
run();API Reference
createTempMailClient(options)
A factory function to create and initialize a client instance.
options(Object): Optional configuration.baseUrl(String): The base URL of the temp mail service. Defaults tohttps://temp-mail.org.lang(String): The language code for API endpoints. Defaults toen.
- Returns:
Promise<TempMailClient>- A promise that resolves to an initialized client instance.
Class: TempMailClient
client.address
- Type:
string - The current temporary email address.
client.mails
- Type:
Array<object> - An array of mail objects currently in the inbox.
async client.init()
- Initializes the client and gets the first email address.
- Returns:
Promise<string>- The new email address.
async client.getMails()
- Refreshes and returns the list of emails in the inbox.
- Returns:
Promise<Array<object>>
async client.getMailBody(mailId)
- Fetches the HTML body of a specific email.
mailId(String): The ID of the email.- Returns:
Promise<string>- The HTML content.
async client.deleteInbox()
- Deletes the current inbox and gets a new one.
- Returns:
Promise<string>- The new email address.
async client.deleteMail(mailId)
- Deletes a specific email from the inbox.
mailId(String): The ID of the email.- Returns:
Promise<boolean>-trueon success.
async client.waitForFirstMail(options)
- Polls the inbox until the first email arrives.
options(Object):timeout(Number): Time to wait in ms. Defaults to60000.interval(Number): Polling interval in ms. Defaults to5000.
- Returns:
Promise<object>- The first mail object. Rejects on timeout.
Author
Created by OpexDev
