MoeMail funktioniert jetzt in deinem KI-Assistenten
MoeMail
Zurück zum Blog

Automated Email Account Creation via API: Test Inboxes in Code (2026)

Every test of a sign-up, password reset or invite flow needs an email address that receives real mail, and a suite that runs in CI needs a fresh one per run. Typing them by hand stops working at the second test. This guide covers the ways to create email accounts automatically, which ones hold up, and a complete example with the MoeMail API. We make MoeMail, so the comparison below includes the options that do not involve us.

What "email account creation" means for tests

You rarely need a full mailbox account with a password and an IMAP login. You need three things from code:

  1. A new address whenever a test starts, so runs never collide.
  2. A way to wait for the message your app sends, without sleeping for a fixed ten seconds.
  3. The content, so the test can pull out a code or a link and continue.

Anything that gives you those three through an API works. Whether the provider calls it an account, an inbox or a mailbox does not matter.

The options, and which ones hold up

ApproachReal mail from the internetSetupGood for
Script Gmail or Outlook sign-upsYesBreaks constantlyNothing: phone checks, CAPTCHAs and the providers' terms stop it
Plus addressing (you+run42@gmail.com)YesNoneManual checks; reading mail back still needs the Gmail API and OAuth
Catch-all on your own domainYesDNS and a mail backendTeams that already run mail infrastructure
Local mail catcher (Mailpit, MailHog)No, only what your app sends over SMTPA containerUnit and integration tests on a laptop or in CI
Temporary inbox APIYesAn API keyEnd-to-end tests against staging or production, and AI agents

The local catcher is the fastest choice when your app can point its SMTP settings at it. As soon as the mail goes out through a real provider such as SES, Resend or Postmark, or the flow is a third-party login, you need an address that the internet can reach. That is what an inbox API gives you.

Create inboxes with the MoeMail API

MoeMail's REST API creates a private mailbox on your account, holds a request open until mail arrives and returns the message as text and HTML. Four calls make a full round trip.

1. Get a key. Sign up, then create a key in your profile under API Key Management. For tests, restrict it: allow only the read and create actions, tick "only the mailboxes this key creates", and set a requests-per-day ceiling so a runaway loop stops at a number you chose.

2. Create, wait, read, delete.

KEY="mk_your_key"

# create a mailbox that expires in one hour (expiryTime is in milliseconds)
curl -s https://moemail.app/api/emails/generate \
  -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"name":"signup-run-42","expiryTime":3600000,"domain":"moemail.app"}'
# {"id":"k3f…","email":"signup-run-42@moemail.app"}

# wait for the verification email: the server holds the request up to 50 seconds
curl -s "https://moemail.app/api/emails/k3f…/wait?timeout=50" -H "X-API-Key: $KEY"
# {"messages":[{"id":"m81…","from_address":"no-reply@example.com","subject":"Confirm your email"}],"cursor":"…"}

# read the message
curl -s https://moemail.app/api/emails/k3f…/m81… -H "X-API-Key: $KEY"
# {"message":{"id":"m81…","content":"Your code is 482913","html":"<p>Your code is…"}}

# delete the mailbox when the test is done
curl -s -X DELETE https://moemail.app/api/emails/k3f… -H "X-API-Key: $KEY"

If wait returns an empty messages list, the timeout passed first. Call it again with since set to the cursor it returned.

Create a batch of addresses in Python

Load tests and fixtures often need many addresses at once. Leave name empty to get a random local part:

import os, time, requests

API = "https://moemail.app/api"
HEADERS = {"X-API-Key": os.environ["MOEMAIL_KEY"]}

def create_inboxes(count, hours=1):
    inboxes = []
    for i in range(count):
        r = requests.post(f"{API}/emails/generate", headers=HEADERS, json={
            "name": "",                        # random address
            "expiryTime": hours * 3600 * 1000,
            "domain": "moemail.app",
        })
        r.raise_for_status()
        data = r.json()
        inboxes.append({"id": data["id"], "email": data["email"]})
        if (i + 1) % 20 == 0:
            time.sleep(60)                     # stay under 20 creations a minute
    return inboxes

for inbox in create_inboxes(5):
    print(inbox["email"])

The one-hour expiry means you do not have to clean up after a crashed run: the mailboxes and their mail are deleted on their own when they expire.

Use it in a Playwright test

The same calls drop into an end-to-end test. This one signs up on your app and reads the code from the email:

import { test, expect } from '@playwright/test'

const API = 'https://moemail.app/api'
const headers = { 'X-API-Key': process.env.MOEMAIL_KEY!, 'Content-Type': 'application/json' }

test('sign-up sends a working code', async ({ page }) => {
  const created = await fetch(`${API}/emails/generate`, {
    method: 'POST',
    headers,
    body: JSON.stringify({ name: '', expiryTime: 3600000, domain: 'moemail.app' }),
  }).then((r) => r.json())

  await page.goto('https://staging.example.com/signup')
  await page.fill('input[name=email]', created.email)
  await page.click('button[type=submit]')

  const waited = await fetch(`${API}/emails/${created.id}/wait?timeout=50`, { headers }).then((r) => r.json())
  const code = waited.messages[0].subject.match(/\d{6}/)?.[0]
  expect(code).toBeTruthy()

  await page.fill('input[name=code]', code!)
  await page.click('button[type=submit]')
  await expect(page.getByText('Welcome')).toBeVisible()

  await fetch(`${API}/emails/${created.id}`, { method: 'DELETE', headers })
})

If the code is in the body rather than the subject, read the message with GET /api/emails/{id}/{messageId} and search its content.

Limits to plan for

  • API calls are paid on moemail.app. The web inbox is free; the API needs a plan with API calls (the Duke role includes 100,000 a month, or buy an API-call pack). Every request counts, including each wait.
  • Creation is rate-limited to 20 new mailboxes a minute, and an account holds a capped number of mailboxes at once; your dashboard shows the cap. Delete mailboxes you are done with, or let short expiries do it.
  • Some sites refuse temporary domains. That is a choice on their side. For your own app it is not a problem; for a third-party flow, check that it accepts the domain.
  • Free and unlimited means self-hosting. MoeMail is open source. Run it on your own Cloudflare account or a server and the same API has no quota, on your own domain.

Use it responsibly

Inboxes on demand are for testing your own products, running QA and giving agents an address for tasks you asked them to do. Do not use them to mass-register accounts on services that do not allow it: that breaks those services' terms and MoeMail's.

AI agents

An agent can use the same API, or connect to MoeMail's hosted MCP server at https://moemail.app/mcp, which exposes create, wait, read and delete as tools and signs in with OAuth instead of a pasted key. See the MCP setup and our comparison of email APIs for agents.

FAQ

Can I create Gmail accounts with an API? No. Google offers no public API for creating consumer Gmail accounts, and scripted sign-ups hit phone verification and CAPTCHAs. Use an inbox API or your own domain instead.

How many addresses can I create? As many as your plan's API calls allow, at up to 20 a minute, within your account's mailbox cap. Mailboxes that expire free up the cap again.

Do the addresses receive mail from any sender? Yes, they are real addresses on public domains, so mail from SES, Gmail or any other sender arrives.

Is there an OpenAPI document? Yes. The temp mail API page links it and lists every endpoint.