Cleaning up after email tests: delete over the API or let retention do it

Updated October 16, 2026 · Zyntra

If every test uses a fresh address and the mail expires on its own, you don't need to clean up: deleting costs a request per email and changes nothing the next test sees. Delete over the API when inboxes are reused (manual QA, seeded users), when emails contain personal data you don't want kept, or when a test checks an empty inbox.

What expires by itself

In Zyntra, mail is deleted automatically after 1 day for addresses never created in the dashboard; 7 days on Free, 30 days on Starter, 90 days on Pro for inboxes created there. A suite that builds a new address per test leaves nothing behind that a later run can trip over.

When deleting is worth it

  • Reused inboxes. A seeded user or a named QA inbox gets mail on every run; a clean inbox makes the next run's "newest email" unambiguous.
  • Personal data. If staging emails carry copied customer data, don't keep it for weeks.
  • Assertions about absence. "Asking for a reset of an unknown address sends nothing" needs an inbox that starts empty.

Deleting over the API

List the inbox (up to 50 emails per page, newest first), then delete each email by its UUID. Each call is one API request.

cleanup.ts
const API = "https://api.zyntra.app";
const headers = { "X-API-Key": process.env.ZYNTRA_API_KEY! };

export async function emptyInbox(inbox: string) {
  for (;;) {
    const res = await fetch(
      `${API}/emails?inbox=${encodeURIComponent(inbox)}&limit=50`,
      { headers },
    );
    const emails: { uuid: string }[] = await res.json();
    if (emails.length === 0) return;
    for (const { uuid } of emails) {
      const del = await fetch(`${API}/emails/message?message_uuid=${uuid}`, {
        method: "DELETE",
        headers,
      });
      if (!del.ok) throw new Error(`Delete failed: ${del.status}`);
    }
  }
}

Run it in a fixture's teardown, not at the start of the next test, so a crashed run does not leave the next one waiting on stale mail.

The cost in requests

Emptying an inbox with ten emails costs eleven requests: one list, ten deletes. On a plan that limits API requests, a teardown on every test can cost more than the tests themselves. Prefer fresh addresses, and keep deletes for the inboxes that really are reused.

Questions

Can an AI agent clean up for me?
Yes. Through Zyntra's MCP server an agent can list an inbox and call delete_email for each message. Each tool call is one API request.