When developing email-related features (registration flows, notifications, parsing), you need test inboxes. Temp mail API is the ideal testing solution. This guide shows how to build an automated email testing environment.
Why Temp Mail for Testing
| Method | Problem | |--------|---------| | Personal email | Limited, pollutes inbox, privacy risk | | Self-hosted mail server | Complex ops, domain reputation issues | | Gmail aliases | Limited, account may be banned | | Temp mail API | Unlimited, disposable, API-friendly |
Each test case gets an independent inbox — no cross-contamination.
Test Environment Setup
const API_BASE = "https://maliapi.215.im/v1";
const API_KEY = process.env.YYDS_API_KEY;
class TempMailTester {
async createAccount() {
const res = await fetch(`${API_BASE}/accounts`, {
method: "POST",
headers: { "X-API-Key": API_KEY },
});
const { data } = await res.json();
this.accountId = data.id;
this.address = data.address;
return data;
}
async waitForMessage(timeout = 30000) {
const start = Date.now();
while (Date.now() - start < timeout) {
const res = await fetch(`${API_BASE}/accounts/${this.accountId}/messages`, {
headers: { "X-API-Key": API_KEY },
});
const { data } = await res.json();
if (data.length > 0) return data[0];
await new Promise((r) => setTimeout(r, 2000));
}
throw new Error("Timeout waiting for email");
}
}
Test Examples
test("user receives verification email after registration", async () => {
const mail = new TempMailTester();
await mail.createAccount();
await registerUser(mail.address, "password123");
const message = await mail.waitForMessage();
expect(message.subject).toContain("verify");
expect(message.text).toMatch(/\d{6}/);
});
Best Practices
- Independent inbox per test: avoid contamination
- Set timeouts: email has delay, 30s is reasonable
- Use Webhook in CI: more reliable than polling
- Clean up: delete temp accounts after tests
- Watch quota: free tier has daily limits, use paid for large CI
FAQ
Does testing consume quota? Yes. Each create/query counts. Free tier for small tests, paid for large CI.
Can I test email sending? No. YYDS Mail is receive-only. Use other tools (like Mailtrap) for sending tests.
Want to build a test environment? See full API docs, or read API getting started.
