Integrating Temp Mail into Tests and CI

The Mail.td REST API is designed for end-to-end testing — verifying signups, password resets, and email-triggered workflows behave correctly. This guide focuses on integration patterns for common test tools.

For the raw endpoint reference (request/response shapes), see the API page or docs.mail.td.

Selenium / Playwright / Cypress

The pattern: create a fresh inbox before each test, sign up your app using that address, then poll the API for the verification email.

// Pseudocode — adapts to any test framework
async function signUpFlow(page) {
  // 1. Create temp mailbox
  const mailbox = await fetch("https://api.mail.td/api/accounts", {
    method: "POST",
    headers: {
      Authorization: "Bearer td_xxx",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      address: `test-${Date.now()}@mail.td`,
      password: "secret"
    })
  }).then(r => r.json());

  // 2. Sign up your app with mailbox.address
  await page.goto("/signup");
  await page.fill("[name=email]", mailbox.address);
  await page.click("button[type=submit]");

  // 3. Poll for the verification email (up to 30s)
  for (let i = 0; i < 30; i++) {
    const list = await fetch(
      `https://api.mail.td/api/accounts/${mailbox.id}/messages`,
      { headers: { Authorization: "Bearer td_xxx" } }
    ).then(r => r.json());
    if (list.messages.length > 0) {
      // List response has no body — fetch the message detail to get text_body
      const msg = await fetch(
        `https://api.mail.td/api/accounts/${mailbox.id}/messages/${list.messages[0].id}`,
        { headers: { Authorization: "Bearer td_xxx" } }
      ).then(r => r.json());
      const link = extractLink(msg.text_body);
      await page.goto(link);
      break;
    }
    await new Promise(r => setTimeout(r, 1000));
  }
}

CI/CD pipelines

For GitHub Actions, GitLab CI, CircleCI, or any pipeline:

  • Store one API token as a CI secret (rotate it from the dashboard if it leaks)
  • Each test job creates its own mailbox — avoids race conditions across parallel jobs
  • Use a unique address per test (e.g. test-${RUN_ID}-${TEST_ID}@mail.td) so failures are easier to debug
  • Tear down nothing — mailboxes auto-expire, no cleanup script needed

Webhooks for faster pipelines (Pro)

Polling adds latency to every test. For long-running test suites, register a webhook URL that receives a POST when new email arrives. Your test waits on the webhook delivery instead of polling 30 times. Cuts a typical 5–15 second wait to under 1 second.

Webhooks are HMAC-SHA256 signed — verify the signature header before processing.

SDK install

npm install mailtd       # Node.js / TypeScript
pip install mailtd       # Python
go get github.com/mailtd/mailtd-go    # Go

For full endpoint reference, see mail.td/api.

Frequently asked questions

Where do I get an API token?

Pro dashboard → API Tokens → Create. Tokens are prefixed `td_` and shown only once at creation — copy and store them in your CI secrets or password manager.

What's the rate limit?

Free is 1 request/second; Pro is 10 requests/second. If you hit the limit, the API returns 429 with a `Retry-After` header.

How do webhook signatures work?

Each webhook POST includes a signature header derived from your webhook secret. Verify the signature before processing the payload to confirm the request came from Mail.td and wasn't tampered with.

Can I run end-to-end tests in parallel?

Yes — give each parallel test job its own mailbox to avoid race conditions. The 100,000 ops/month Pro quota covers most CI use cases.

Does the API work for Free accounts?

Free includes 500 API operations per month — suitable for light scripting. For CI/CD or anything that needs higher throughput, upgrade to Pro for 100,000 ops/month and a higher request rate.