Home Unlimited API FAQ GitBook Contact About Us Menu 4.7 on

REST API

We understand the importance of integrating our email verification solution seamlessly into your existing systems. That's why we offer a robust REST API that allows you to easily integrate our email verification capabilities into any other solution.

Upgrading to the unlimited version of MailTester.ninja offers high speed access to the REST API, allowing you to automate your email address verification process and improve efficiency.

MailTester Ninja REST API

Method

					GET
				

Authentication Token

Your unlimited key without {}

					https://token.mailtester.ninja/token?key=yourkey
				

Token Response

					{
"product":"E",
"token":"Mk5ETGRlQnd3WkZYOGszWXlwQV...WDhQR0pJU0tLa1R4WW5BbXRJVA==",
"message":"Your key is enabled: {sub_.....O3gC6}",
"portal":"7sI7....cMbII"
}
				

API endpoint

					https://happy.mailtester.ninja/ninja
				

Parameters

The email address you are verifying: email (required)

Your authentication token: token (required) (valid 24h)

					https://happy.mailtester.ninja/ninja?email=john.doe@email.com&token=yourtoken
				

API Response

					{
	"email": "john.doe@email.com",
	"user": "John Doe",
	"domain": "email.com",
	"mx": "mx.sender-email.com",
	"code": "ok",
	"message": "Accepted",
	"api": 5,
	"connections": 1
}
				

Our API is designed to be simple and intuitive, allowing you to quickly and easily verify email addresses without any complex coding or setup.

With our API, you can streamline your email verification process, improve your communication strategy, and reduce bounce rates, all while maintaining the security and privacy of your data.

The free version of the API without a key is limited to verifying 1 email per minute. For the unlimited version with a key, the rate limit is 3 emails every 2 seconds, allowing for much faster and more efficient email verification.

So, whether you're looking to integrate email verification into your CRM, email marketing tool, or any other solution, our API makes it easy to get started. Sign up today and start using our advanced email verification tools to take your communication strategy to the next level.

How to Use the Email Verification API with Node.js

Follow the steps below to integrate your email verification API with Node.js and verify a list of email addresses.

NodeJs Script (mailtester.cjs)

	
// A simple Node JS Script to use MailTester Ninja API
// Save this to mailtester.cjs

/*
 * Installation and Setup Guide for Node.js, PM2, and PM2 Logrotate
 * ================================================================
 *
 * 1. Install Node.js
 * ------------------
 * Windows:
 * - Download the installer from the official website: https://nodejs.org/
 * - Run the installer and follow the setup wizard.
 * - Verify installation: open a terminal and type `node -v` and `npm -v`.
 *
 * Linux:
 * - Update package lists: `sudo apt update` (for Debian/Ubuntu-based systems).
 * - Install Node.js via package manager:
 *   Option 1 (NodeSource):
 *     - Add NodeSource: `curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -`
 *     - Install: `sudo apt install -y nodejs`
 *   Option 2 (nvm):
 *     - Install nvm: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash`
 *     - Load nvm: `source ~/.bashrc`
 *     - Install Node.js: `nvm install --lts`
 * - Verify installation: `node -v` and `npm -v`.
 *
 * 2. Install PM2
 * --------------
 * - Globally install PM2 using npm: `npm install -g pm2`
 * - Verify PM2 installation: `pm2 -v`
 *
 * 3. Install PM2 Logrotate
 * ------------------------
 * - Install the logrotate module: `pm2 install pm2-logrotate`
 * - Configure logrotate:
 *   - Adjust settings: `pm2 set pm2-logrotate:max_size 10M` (rotate logs when they exceed 10MB).
 *   - Set retention: `pm2 set pm2-logrotate:retain 30` (keep logs for 30 days).
 *
 * 4. Start your Nodejs Script
 * -------------------------
 * - Navigate to your project directory: `cd /path/to/your/project`
 * - Save this code to mailtester.cjs and set your key in the code.
 * - Run `npm install` this will install all dependencies (csv writer, axos, fs etc.)
 * - Start the script with PM2: `pm2 start mailtester.cjs`
 * - View running processes: `pm2 list`
 * - Save the PM2 process list to restart it on reboot: `pm2 save`
 *
 * 5. Enable PM2 Startup on System Boot
 * ------------------------------------
 * Windows:
 * - PM2 does not have native startup scripts for Windows.
 * Linux:
 * - Generate and enable a startup script:
 *   `pm2 startup systemd`
 *   - Follow the instructions provided to complete the setup.
 *
 * 6. View Logs
 * ------------
 * - Display logs in real time: `pm2 logs`
 * - View logs for a specific process: `pm2 logs `
 *
 * Notes:
 * - PM2 log files are stored by default in `~/.pm2/logs/`.
 * - Use `pm2 flush` to clear all logs.
 *
 * 7. Stop or Delete a Process
 * ---------------------------
 * - Stop a process: `pm2 stop `
 * - Delete a process: `pm2 delete `
 */


const fs = require('fs');
const axios = require('axios');

const filePath1 = './mails.txt';  // Input Path
const filePath2 = './output.csv'; // Output Path

// Your Unlimited acces key
const key = 'Your key without {}';

const { createObjectCsvWriter } = require('csv-writer');

// CSV Path
const csvFilePath = './output.csv';

// CSV Writer Setup
const csvWriter = createObjectCsvWriter({
    path: csvFilePath,    
    header: [
      { id: 'email', title: 'Email' },
      { id: 'code', title: 'Code' },
      { id: 'message', title: 'Message' },
      { id: 'user', title: 'User' },
      { id: 'domain', title: 'Domain' }
    ],
    append: true,
});

// Extract all email from a text file. It's magic, no matter your file format, no matter it's content.
function extractEmailsFromFile(filePath) {
    const fileContent = fs.readFileSync(filePath, 'utf8');
    const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
    const emails = fileContent.match(emailRegex);
    return emails || [];
}

// Get your authentication token
async function getToken() {
  let uri = `https://token.mailtester.ninja/token?key=${key}`;
  return await axios.get(uri,{family:4}).then((res) => {
    let data = res.data;
    return data.token;
  }).catch(error => {console.log("Invalid Key", error); return null;});
}

// API Query
async function doGetRequest(email, token, i) {
  let uri = `https://happy.mailtester.ninja/ninja?email=${email}&token=${token}`;

  axios.get(uri,{family:4}).then(async (res) => {
    let data = res.data;
    await csvWriter.writeRecords([data]); 
  }).catch(error => {console.log("error", error.toString().substring(0,200), uri)});
}

// Main loop
async function start() {
  const token = await getToken();
  const startDate = new Date();

  // Extract Emails from Input & Output
  let emailArray =  extractEmailsFromFile(filePath1);
  const emailArrayDone =  extractEmailsFromFile(filePath2);

  // Remove all emails already checked
  const emailArrayToSet = new Set(emailArrayDone);
  emailArray = emailArray.filter(element => !emailArrayToSet.has(element));
  
  for (let i = 0; i < emailArray.length; i++) {
    const email =  emailArray[i];

    // A little bit of logging 
    console.log(`Query ${i} ${email}`);
    console.log('Timer (minutes) ', (((new Date() - startDate)) / 1000 / 60).toFixed(2));

    doGetRequest(email, token,i);

    // Throttle (100k / Day equivalent)
    await new Promise((resolve) => {setTimeout(resolve, 800)});
  };
  
  const endDate = new Date();
  console.log('Started at', startDate);
  console.log('Ended at', endDate);
}

// Let's go to party !!!
start();


Installation and Execution Instructions

We have included all required instructions as comments at the beginning of our script. 💪

This NodeJS script verifies a list of email addresses using MailTester Ninja API, then generates and displays the results in a CSV file. You can integrate this code or adapt it according to your needs.