developers 10 min read

Temp Mail API: The Complete Developer Guide

P
Pokemail Team
Code brackets containing an email envelope representing temporary email API for developers
đź“‘ In This Article

Automated testing, CI/CD pipelines, and email verification flows all need real email addresses that can receive real messages. Hardcoding a single test email creates bottlenecks, data pollution, and flaky tests. A temp mail API solves this by generating fresh disposable inboxes programmatically, on demand, at scale.

Why Developers Need a Temp Mail API

Every application with user registration needs testing. Manual testing with personal email addresses doesn’t scale. You can’t run 50 signup tests per deployment cycle with one Gmail account without creating a tangled mess of test data.

A temp mail API gives you a fresh, unique email address for every test run. Each address receives actual emails, can be read programmatically through HTTP endpoints, and is automatically cleaned up when the session expires. No shared state between tests, no data pollution, and no manual cleanup.

The most common use cases include end-to-end testing of signup and onboarding flows, automated verification of email delivery in CI/CD pipelines, load testing email-dependent features with many concurrent users, QA testing across multiple user accounts simultaneously, and integration testing for transactional email systems like password resets, invoices, and notifications. If you’re testing signup flows manually first, our guide on using disposable email for signups covers the manual process, while this guide covers automation.

For a non-technical overview of how temporary email works and what makes a service safe to use, see our complete guide to temporary email.

Basic Temp Mail API Workflow

The typical integration follows three steps. First, create a temporary address by calling the API. Second, use that address in your test by submitting it to a signup form, triggering an email send, or whatever your test requires. Third, read the inbox to extract what you need, whether that’s a verification code, magic link, or confirmation message.

Here’s a minimal example in JavaScript:

// 1. Create a temporary address
const res = await fetch("https://pokemail.app/api/v1/addresses", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ domain: "pokemail.app" }),
});
const { data } = await res.json();
const address = data.address;

// 2. Use the address in your test
await yourApp.signup(address, "testpassword123");

// 3. Wait for and read the verification email
await new Promise(r => setTimeout(r, 5000));
const inbox = await fetch(
  `https://pokemail.app/api/v1/inbox/${encodeURIComponent(address)}`,
  { headers: { "Authorization": "Bearer YOUR_API_KEY" } }
);
const emails = (await inbox.json()).data.emails;
const verificationCode = extractCode(emails[0].subject);

And the same workflow in Python:

import requests
import time

API_KEY = "YOUR_API_KEY"
BASE = "https://pokemail.app/api/v1"
headers = {"Authorization": f"Bearer {API_KEY}"}

# 1. Create address
res = requests.post(f"{BASE}/addresses",
    headers=headers,
    json={"domain": "pokemail.app"})
address = res.json()["data"]["address"]

# 2. Use in test
your_app.signup(address, "testpassword123")

# 3. Poll for email
def wait_for_email(address, timeout=60, interval=3):
    deadline = time.time() + timeout
    while time.time() < deadline:
        res = requests.get(
            f"{BASE}/inbox/{requests.utils.quote(address)}",
            headers=headers)
        if res.status_code == 429:
            time.sleep(int(res.headers.get("Retry-After", 10)))
            continue
        data = res.json()
        if data["data"]["count"] > 0:
            return data["data"]["emails"]
        time.sleep(interval)
    raise TimeoutError(f"No email at {address} within {timeout}s")

emails = wait_for_email(address)
code = extract_verification_code(emails[0]["body"])

Extracting Verification Codes

The trickiest part of email-based testing is extracting the verification code or magic link from the email body. Different platforms use different formats, and those formats change over time without warning.

Common patterns include six-digit numeric codes in the subject line or body, UUID-based verification URLs embedded in HTML links, one-time password tokens in plain text sections, and magic links that contain the entire auth token in the URL.

The best approach is to build a small extraction library that handles each pattern with focused regex rules. Keep this library separate from your test logic so you can update extraction patterns as services change their email templates without touching your test suite.

// Example extraction helpers
function extractNumericCode(text) {
  const match = text.match(/\b(\d{4,8})\b/);
  return match ? match[1] : null;
}

function extractVerifyLink(html) {
  const match = html.match(/href="(https?:\/\/[^"]*verify[^"]*)"/i);
  return match ? match[1] : null;
}

function extractMagicLink(html) {
  const match = html.match(/href="(https?:\/\/[^"]*token=[^"]*)"/i);
  return match ? match[1] : null;
}

Webhook-Based Integration

Polling the inbox introduces latency and adds complexity to your test code. If your temp mail API plan supports webhooks, you can eliminate polling entirely and receive a push notification the instant an email arrives.

Register a webhook URL with the API, and whenever an email arrives at any of your generated addresses, the API sends a POST request to your server with the email metadata. Your test can then fetch the full email content and proceed immediately, cutting test execution time from “poll every 3 seconds for up to 60 seconds” down to “respond within 1 second of delivery.”

Webhooks are especially valuable in CI/CD environments where test parallelism means dozens of emails arriving within the same minute. Instead of managing polling loops for each address, your webhook handler dispatches each email to the correct test context as soon as it lands.

CI/CD Integration

For continuous integration pipelines, create a helper module that your test framework can import. This module should handle address creation, inbox reading with configurable timeouts, verification code extraction, and session cleanup. Most test frameworks like Jest, Playwright, Cypress, and pytest support setup and teardown hooks where you can create and destroy temp addresses automatically.

Keep your API key in environment variables or a secrets manager. Never commit it to your repository, and never log it in test output.

// Example: Playwright helper
const { test } = require("@playwright/test");

test.beforeEach(async ({ page }, testInfo) => {
  const address = await createTempAddress();
  testInfo.tempEmail = address;
});

test("user can sign up and verify email", async ({ page }, testInfo) => {
  await page.goto("/signup");
  await page.fill("#email", testInfo.tempEmail);
  await page.fill("#password", "TestPassword123!");
  await page.click("#submit");

  const emails = await waitForEmail(testInfo.tempEmail);
  const code = extractNumericCode(emails[0].subject);

  await page.fill("#verification-code", code);
  await page.click("#verify");
  await expect(page.locator(".welcome")).toBeVisible();
});

Disposable Email List API (Detection)

On the other side of the equation, some developers need to check whether an email address belongs to a disposable provider. A disposable email list API, sometimes called a disposable email checker API, handles this by comparing email domains against databases of known temporary email services.

How a Disposable Email Checker API Works

The typical flow is simple. You send a GET or POST request containing the email address you want to check. The API extracts the domain, compares it against its database, and returns a result indicating whether the domain is associated with a disposable email provider.

// Example: Check if an email is disposable
const check = await fetch(
  "https://api.example.com/check-disposable",
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ email: "user@example.com" }),
  }
);
const result = await check.json();
// { "disposable": false, "domain": "example.com" }

Most disposable email checker APIs respond in under 100 milliseconds, making them fast enough to integrate into real-time registration flows without adding noticeable latency to the user experience.

Use Cases for Detection APIs

Disposable email detection is useful for analytics (understanding what percentage of your signups use temp addresses), fraud prevention on marketplaces and financial platforms, and user segmentation where you want to distinguish between users who provided permanent addresses and those who used temporary ones.

The detection data can inform product decisions too. If a high percentage of your trial signups use disposable email, that’s a signal that your email requirements might be a barrier to conversion, and simplifying the signup flow could increase retention.

Rate Limits and Scaling

Temp mail APIs typically implement rate limits based on your subscription tier. For local development, you’ll rarely hit these limits. For CI/CD environments running parallel test suites with dozens of concurrent address creations, you might.

Strategies to work within rate limits include reusing addresses across sequential tests in the same suite when isolation isn’t critical, adding small delays between rapid address creation calls, batching address creation at the start of the test run rather than creating on demand, and upgrading to a higher-tier plan that matches your CI/CD concurrency level.

Most well-designed APIs include rate limit headers in every response (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset) so you can implement proactive throttling rather than reactive retry logic.

Error Handling Best Practices

Email delivery is inherently asynchronous and occasionally unpredictable. Your test suite should handle common failure modes gracefully.

For email delivery delays, set a reasonable timeout of 30 to 60 seconds for most platforms, with polling every 2 to 3 seconds. If the timeout expires, fail the test with a clear message that distinguishes “email never arrived” from “email arrived but content didn’t match expectations.”

When templates change (and they will), your extraction regex breaks. Log the full email body on extraction failure so you can update your patterns quickly, and avoid overly specific regex that cracks on minor formatting changes.

For rate limit responses, implement exponential backoff when you receive a 429 status code. Most APIs include a Retry-After header telling you exactly when to retry.

⚠️ Your API key has access to all temporary inboxes created under your account. Treat it like any other credential: store it securely in environment variables or a secrets manager, rotate it periodically, and restrict access to only the systems that need it.

Choosing the Right Temp Mail API

When evaluating temp mail APIs for your development workflow, prioritize delivery speed (WebSocket-based services deliver sub-second), webhook support for CI/CD, clear documentation with working code examples, transparent pricing at the scale you need, and rate limit headers in every response.

For a broader comparison of temporary email services and their features, see our review of the best services available. For the basics of how temporary email works, see why disposable email matters. For a quick start with the Pokemail API specifically, see our developer API quickstart guide.

đź“§
Try Pokemail

Free temporary email in one click. No registration, no tracking. Auto-deletes in 60 minutes.

Get Your Inbox →

Frequently Asked Questions

What is a temp mail API?

A temp mail API lets you create disposable email addresses and read their inboxes programmatically through HTTP endpoints. Developers use them for automated signup testing, CI/CD pipeline email verification, and any application that needs to generate and read emails as part of its workflow.

What is a disposable email list API?

A disposable email list API, also called a disposable email checker API, checks whether an email address belongs to a known temporary email provider. Website operators use these to identify signups from disposable addresses for analytics, fraud prevention, or user segmentation.

How does a disposable email checker API work?

You send an HTTP request containing the email address you want to check. The API compares the domain against a database of known disposable email providers and returns a boolean result along with metadata like the provider name and confidence score. Most checker APIs respond in under 100 milliseconds.

Can I use webhook notifications instead of polling?

Yes, some temp mail API plans support webhooks. Instead of polling the inbox every few seconds, the API sends a POST request to your server the instant an email arrives. This makes tests faster, more reliable, and eliminates the complexity of polling loops.

What are the best temp mail APIs for CI/CD?

Look for APIs with fast delivery via WebSocket, webhook support for real-time notifications, multiple domains for rotation, clear rate limit headers, and good documentation. Pokemail's API offers all of these with sub-second email delivery.