TempMail API for JavaScript is Ready!

Ever wanted to make a program that interacted with TempMail.lol but didn’t want to figure out the API yourself? Now, you can use our basic JavaScript/TypeScript library to do so!

Ever wanted to make a program that interacted with TempMail.lol but didn’t want to figure out the API yourself? Now, you can use our basic JavaScript/TypeScript library to do so!

To get started, install the library on your project:

npm i tempmail.lol

You can also use Yarn if you prefer.

yarn add tempmail.lol

Important – Read Before Using

Inboxes have a hard expiration time of one hour. If you do not use the token to check for emails within 10 minutes of the last check, the inbox will expire.

Usage

Using the API is very simple. To create an inbox, use the following code:

const {createInbox} = require("tempmail.lol");

createInbox((inbox, err) => {
    if(err) {
        return console.error(err);
    }
    
    console.log(`Created new inbox: ${inbox.address}`);
    console.log(`Inbox token: ${inbox.token}`);
});

Or you can use promises if you prefer:

const inbox = await createInboxAsync();
//or you can use .then()

Make sure to save either the Inbox or the token returned, as you will need it to access any received emails.

To access received emails:

const {checkInbox} = require("tempmail.lol");

checkInbox("YOUR_TOKEN", (emails, err) => { //you can also pass in the Inbox object.
    if(err) {
        return console.error(err);
    }
    
    emails.forEach((e) => {
        console.log(JSON.stringify(e, null, 4));
    });
});

Of course, you can also use the async method:

const emails = checkInboxAsync("YOUR_TOKEN"); //you can also pass in the Inbox object.

Note: if the token is invalid, the checkInbox and checkInboxAsync methods will throw an error. Keep this in mind for when you use it in production.

Examples

I learn from examples, and you might as well! Here is an example program that generates an email, checks for new emails every 10 seconds, then displays if any are received.

const {createInbox, checkInboxAsync} = require("tempmail.lol");

createInbox((inbox, err) => {
    if(err) {
        return console.log(err);
    }
    
    console.log(`Inbox created: ${inbox.address}`);
    
    //Check for new emails every 10 seconds
    setInterval(async () => {
        const emails = await checkInboxAsync(inbox);
        
        if(emails.length > 0) {
            console.log(`${emails.length} emails received`);
            
            //print out each email.
            emails.forEach((value, index) => {
                console.log(`${index + 1}: ${value.subject}`);
                console.log(`from: ${value.from}`);
                console.log(`date sent: ${new Date(value.date)}`);
                console.log(`body: ${value.body}`);
                console.log(`html: ${value.html}`); //note: html may be undefined.
            });
        }
    }, 10000);
});

Pretty cool! Let me know what you end up creating, you can reach me at [email protected].