Guides Developer Guide

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. DevInbox provides a robust API that integrates seamlessly with your existing testing frameworks.

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

Step 1: Get Your API Key

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

  1. 1. Sign up for a free DevInbox 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 DEVINBOX_API_KEY="your-api-key-here"

# Or in your test configuration
import os

API_KEY = os.getenv("DEVINBOX_API_KEY")
API_BASE = "https://api.devinbox.io"

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 @devinbox.io) as the username and the password for authentication with smtp.devinbox.io:587.

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.devinbox.io/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']}@devinbox.io")
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 DevInbox:

Option 1: Configure SMTP Server in Your Application

Configure your application's SMTP settings to use DevInbox's SMTP server with the credentials returned by the Create Mailbox API. Set the SMTP server to smtp.devinbox.io: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 DevInbox and delivered to your mailbox.

Option 2: Send Directly to Mailbox Address

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

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 DevInbox credentials
# Configure your app to use smtp.devinbox.io:587 with mailbox key/password
# All emails sent by your app will be captured by DevInbox
smtp_server = "smtp.devinbox.io"
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 DevInbox
    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@devinbox.io
test_email = f"{mailbox['key']}@devinbox.io"
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.devinbox.io/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 →

What's Next?