Developer Guide

Integration testing for developers - API-driven email testing in your applications

Perfect for Automated Testing

Generate disposable emails programmatically and verify email content in your test suites. FounderMail provides a robust API that integrates seamlessly with your existing testing frameworks.

Why Use FounderMail for Integration Testing? Traditional email testing is slow, unreliable, and requires complex setup. FounderMail provides instant, isolated email addresses that work perfectly in automated test environments.

Step 1: Get Your API Key

Before you can use the FounderMail API, you need to obtain an API key from your dashboard.

  1. 1. Sign up for a free FounderMail account
  2. 2. Navigate to Settings → API Keys
  3. 3. Click Generate API Key
  4. 4. Copy and store it securely in your test environment
All API requests require authentication via the X-Api-Key header. Keep your API key secure and never commit it to version control.
# Store your API key as environment variable
$ export FOUNDERMAIL_API_KEY="your-api-key-here"

# Or in your test configuration
import os

API_KEY = os.getenv("FOUNDERMAIL_API_KEY")
API_BASE = "https://api.foundermail.mx"

Step 2: Create a Temporary Mailbox

Create a disposable mailbox that will receive your test emails. Each mailbox gets a unique email address and password for SMTP authentication.

Temporary mailboxes are perfect for integration tests that need isolated, thread-safe email addresses.

Optional: You can specify a projectName to organize mailboxes. If not provided, your default project will be used.

SMTP Note: For direct SMTP sending, use the mailbox key (without @foundermail.mx) as the username and the password for authentication with smtp.foundermail.mx:587. Mail submitted this way is captured in the mailbox rather than delivered, unless the mailbox is switched to relay mode.

import requests

API_KEY = "your_api_key"
headers = {"X-Api-Key": API_KEY}

# Create a temporary mailbox (uses default project)
response = requests.post(
    "https://api.foundermail.mx/mailboxes",
    headers=headers,
    json={})

# Or specify a project: json={"projectName": "MyProject"}

mailbox = response.json()
print(f"Mailbox Key: {mailbox['key']}")
print(f"Email Address: {mailbox['key']}@foundermail.mx")
print(f"Password: {mailbox['password']}"

Step 3: Trigger Your Application

Now that you have a mailbox, you have two options to send emails that will be captured by FounderMail:

Option 1: Configure SMTP Server in Your Application

Configure your application's SMTP settings to use FounderMail's SMTP server with the credentials returned by the Create Mailbox API. Set the SMTP server to smtp.foundermail.mx:587, use the mailbox key as the username, and the password for authentication. Your application can then send emails to any recipient address, and all emails will be captured by FounderMail and delivered to your mailbox — nothing reaches the recipients you addressed. (A mailbox switched to relay mode behaves the opposite way; see below.)

Option 2: Send Directly to Mailbox Address

Alternatively, you can configure your application to send emails directly to the mailbox address ({key}@foundermail.mx). Any emails sent to this address will be automatically captured by FounderMail.

Sending for real: SMTP relay mode

Every persistent mailbox has an SMTP mode. Capture is the default and is what the two options above describe: submitted mail is stored in the mailbox and delivered to nobody, which is what a test suite wants. Relay makes the mailbox a real one — submitted mail leaves for its actual recipients, from the mailbox's own address, DKIM-signed for its domain.

Switch a mailbox with Send mail for real on its dashboard page. With relay on, a normal mail client can read the mailbox over IMAP and send from it over SMTP, so replies go out as the address they were sent to — no Gmail send-as, no separate DMARC setup per domain. A mailbox on a custom domain needs sending enabled for that domain first, so its DKIM records are published and verified.

Relayed mail counts against your plan's monthly outbound allowance, and free plans are reply-only: a relayed message must answer one the mailbox received.

Pro tip: Add a small delay (100-500ms) after triggering your application to ensure the email has been delivered before checking for it.
import time
import smtplib
from email.mime.text import MIMEText

# Option 1: Configure your app's SMTP server with FounderMail credentials
# Configure your app to use smtp.foundermail.mx:587 with mailbox key/password
# All emails sent by your app will be captured by FounderMail
smtp_server = "smtp.foundermail.mx"
smtp_port = 587
username = mailbox['key']  # Use key as username
password = mailbox['password']  # Use returned password

# Your app can now send emails normally - they'll all be captured
with smtplib.SMTP(smtp_server, smtp_port) as server:
    server.starttls()
    server.login(username, password)
    # Send to any recipient - all emails are captured by FounderMail
    server.sendmail(username, "any-recipient@example.com", "Test email body")

# Option 2: Send directly to the mailbox address
# Configure your app to send emails to key@foundermail.mx
test_email = f"{mailbox['key']}@foundermail.mx"
your_app.register_user(
    email=test_email,
    name="John Doe")

# Wait for email delivery
time.sleep(0.3)  # 300ms

Step 4: Verify the Email

Retrieve and verify the email from your mailbox. You can check the subject, body, sender, and any other email properties your test requires.

Use /single when you expect exactly one email, or /last to get the most recent email.
# Get the single message (fails if 0 or >1 messages)
response = requests.get(
    f"https://api.foundermail.mx/messages/{mailbox['key']}/single",
    headers=headers)

message = response.json()

# Verify email content
assert "Welcome" in message['subject']
assert "John Doe" in message['body']
assert message['from'][0] == "noreply@yourapp.com"

print("✓ Email verification passed!"

Advanced Testing Features

Template Verification

Verify emails follow specific templates and extract structured data.

Learn about templates →

Webhook Integration

Get real-time notifications when emails are received.

Configure webhooks →

GitHub Repositories

Explore our open-source SDKs and contribute to the FounderMail ecosystem on GitHub.

What's Next?