TempMail

How to Use TempMail API for Automated Testing

How to Use TempMail API for Automated Testing

Complete guide to integrating TempMail's REST API into your automated test suite with examples in cURL, JavaScript, and Python.

Why Use an Email API for Testing?

Automated testing often requires email verification -- confirming sign-ups, testing password resets, validating notification emails. Instead of managing real email accounts, use TempMail's API to create disposable addresses programmatically.

Quick Start

1. Generate a Random Email

No API call needed -- just construct any address using an active domain:

testuser123@mailmomy.com

2. Fetch Emails

curl "https://mailmomy.com/api/mail/messages?to=testuser123@mailmomy.com"

Response:

{
  "emails": [
    {
      "id": "uuid-here",
      "from": "noreply@example.com",
      "subject": "Verify your email",
      "message": "<html>...</html>",
      "receivedAt": "2026-03-08 10:30:00"
    }
  ],
  "total": 1,
  "page": 1,
  "limit": 20,
  "pages": 1
}

3. Clean Up

curl -X DELETE "https://mailmomy.com/api/mail/delete?to=testuser123@mailmomy.com"

JavaScript Example

async function waitForEmail(address, timeout = 30000) {
  const start = Date.now();
  while (Date.now() - start < timeout) {
    const res = await fetch(`/api/mail/messages?to=${address}`);
    const data = await res.json();
    if (data.emails.length > 0) return data.emails[0];
    await new Promise(r => setTimeout(r, 2000));
  }
  throw new Error('Email not received within timeout');
}

Python Example

import requests
import time

def wait_for_email(address, timeout=30):
    start = time.time()
    while time.time() - start < timeout:
        r = requests.get(f'https://mailmomy.com/api/mail/messages?to={address}')
        data = r.json()
        if data['emails']:
            return data['emails'][0]
        time.sleep(2)
    raise TimeoutError('Email not received')

Full API Reference

Check our complete API Documentation for all available endpoints including pagination, single email deletion, and domain management.

← Back to Blog