Integration testing for developers - API-driven email testing in your applications
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.
Traditional email testing is slow, unreliable, and requires complex setup. DevInbox provides instant, isolated email addresses that work perfectly in automated test environments.
Before you can use the DevInbox API, you need to obtain an API key from your dashboard.
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" Store your API key as environment variable
export DEVINBOX_API_KEY="your-api-key-here"
Or in your test configuration
const API_KEY = process.env.DEVINBOX_API_KEY;
const API_BASE = 'https://api.devinbox.io'; Store in appsettings.json or user secrets
{
"DevInbox": {
"ApiKey": "your-api-key-here",
"ApiBase": "https://api.devinbox.io"
}
}
Or use environment variables
var apiKey = Environment.GetEnvironmentVariable("DEVINBOX_API_KEY"); Store your API key as environment variable
export DEVINBOX_API_KEY="your-api-key-here"
Or in your test configuration
import "os"
apiKey := os.Getenv("DEVINBOX_API_KEY")
apiBase := "https://api.devinbox.io"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 stored in Redis and automatically expire after 24 hours. They're 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']}")const API_KEY = 'your_api_key';
const headers = { 'X-Api-Key': API_KEY };
Create a temporary mailbox (uses default project)
const response = await fetch(
'https://api.devinbox.io/mailboxes',
{
method: 'POST',
headers: {
...headers,
'Content-Type': 'application/json'
},
body: JSON.stringify({})
// Or: body: JSON.stringify({ projectName: 'MyProject' })
});
const mailbox = await response.json();
console.log(`Mailbox Key: ${mailbox.key}`);
console.log(`Email: ${mailbox.key}@devinbox.io`);using System.Net.Http;
using System.Text;
using System.Text.Json;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-Api-Key", "your_api_key");
Create a temporary mailbox (uses default project)
var payload = new { };
// Or specify project: var payload = new { projectName = "MyProject" };
var content = new StringContent(
JsonSerializer.Serialize(payload),
Encoding.UTF8,
"application/json");
var response = await client.PostAsync(
"https://api.devinbox.io/mailboxes", content);
var mailbox = await response.Content.ReadFromJsonAsync<dynamic>();
Console.WriteLine($"Email: {mailbox.key}@devinbox.io");package main
import (
"bytes"
"encoding/json"
"net/http"
)
Create empty payload (uses default project)
payload := map[string]string{}
Or specify project: payload := map[string]string{"projectName": "MyProject"}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST",
"https://api.devinbox.io/mailboxes",
bytes.NewBuffer(jsonData))
req.Header.Set("X-Api-Key", "your_api_key")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
Now that you have a mailbox, configure your application to send emails to it. Use the mailbox email address ({'{key}'}@devinbox.io) as the recipient.
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
Trigger your application's email functionality
Example: User registration
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 Trigger your application's email functionality
Example: User registration
const testEmail = `${mailbox.key}@devinbox.io`;
await yourApp.registerUser({
email: testEmail,
name: 'John Doe'
});
Wait for email delivery
await new Promise(r => setTimeout(r, 300)); // 300ms Trigger your application's email functionality
Example: User registration
var testEmail = $"{mailbox.key}@devinbox.io";
await yourApp.RegisterUserAsync(
email: testEmail,
name: "John Doe");
Wait for email delivery
await Task.Delay(300); // 300msimport "time"
Trigger your application's email functionality
Example: User registration
testEmail := fmt.Sprintf("%s@devinbox.io", mailbox.Key)
yourApp.RegisterUser(
email: testEmail,
name: "John Doe")
Wait for email delivery
time.Sleep(300 * time.Millisecond)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!") Get the single message (fails if 0 or >1 messages)
const response = await fetch(
`https://api.devinbox.io/messages/${mailbox.key}/single`,
{ headers });
const message = await response.json();
Verify email content
expect(message.subject).toContain('Welcome');
expect(message.body).toContain('John Doe');
expect(message.from[0]).toBe('noreply@yourapp.com');
console.log('✓ Email verification passed!'); Get the single message (fails if 0 or >1 messages)
var response = await client.GetAsync(
$"https://api.devinbox.io/messages/{mailbox.key}/single");
var message = await response
.Content.ReadFromJsonAsync<dynamic>();
Verify email content
Assert.Contains("Welcome", message.subject.ToString());
Assert.Contains("John Doe", message.body.ToString());
Assert.Equal("noreply@yourapp.com", message.from[0].ToString());
Console.WriteLine("✓ Email verification passed!"); Get the single message (fails if 0 or >1 messages)
url := fmt.Sprintf(
"https://api.devinbox.io/messages/%s/single",
mailbox.Key)
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("X-Api-Key", apiKey)
resp, _ := client.Do(req)
var message Message
json.NewDecoder(resp.Body).Decode(&message)
Verify email content
assert.Contains(t, message.Subject, "Welcome")
assert.Contains(t, message.Body, "John Doe")Verify emails follow specific templates and extract structured data.
Learn about templates →Explore more advanced features and integration patterns for your development workflow.