How to test emails in GitHub Actions

· 5 min read · QuickInbox team

  • GitHub Actions
  • CI
  • Email testing

Email tests that only run locally miss the moment they matter most: when someone changes the template or the mail settings in a pull request.

Free API or Business API?

The free API is fine for a few tests, but GitHub runners share IP addresses and the free API allows about 10 new addresses per minute per IP. For CI, private inboxes from the Business API are more reliable: any namespace.tag@quickinbox.net works without a create call, and only your key can read it.

Step 1: secrets

In Settings > Secrets and variables > Actions add QI_KEY (a key made for CI) and QI_NAMESPACE.

Step 2: the helper

// inbox.js - private test inboxes with the Business API (Node 18+)
const BASE = 'https://business.quickinbox.net';
const NS = process.env.QI_NAMESPACE;            // e.g. "acme7x"
const auth = { headers: { 'X-API-Key': process.env.QI_KEY } };

// Any tag works at once: acme7x.<tag>@quickinbox.net
export function newAddress(prefix = 'test') {
  const tag = `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
  return { tag, address: `${NS}.${tag}@quickinbox.net` };
}

export async function waitForEmail(tag, { timeoutMs = 60_000, subject = '' } = {}) {
  const since = Math.floor(Date.now() / 1000) - 60;
  const deadline = Date.now() + timeoutMs;
  while (Date.now() < deadline) {
    const res = await fetch(`${BASE}/api/business/mail?namespace=${NS}&since=${since}&limit=50`, auth);
    if (res.ok) {
      const { messages } = await res.json();
      const hit = messages.find((m) => m.to === `${NS}.${tag}` && m.subject.includes(subject));
      if (hit) return hit; // id, to, from, subject, text, html, spam, receivedAt
    }
    await new Promise((r) => setTimeout(r, 2000));
  }
  throw new Error(`No email for ${tag} within ${timeoutMs} ms`);
}

Step 3: the workflow

# .github/workflows/e2e.yml
name: e2e
on: [pull_request]
jobs:
  e2e:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx playwright install --with-deps chromium
      - run: npx playwright test
        env:
          QI_KEY: ${{ secrets.QI_KEY }}
          QI_NAMESPACE: ${{ secrets.QI_NAMESPACE }}
          BASE_URL: https://staging.example.com
      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: playwright-report
          path: playwright-report

Tips

  • Put the run id in the tag (newAddress(`pr-${process.env.GITHUB_RUN_ID}`)) so you can find a run's emails in your workspace.
  • Use the webhook or the live stream instead of polling if you have many email tests. See receiving email by webhook.
  • Set retention on your CI namespace to a few days so old test mail clears itself.

Related guides

Get private inboxes: the QuickInbox Business API has a free plan with 5,000 emails a month, and paid plans from $9. Create a free account or read the API docs.

← All articles