Learn how to integrate DevInbox into your automated test suites to verify email functionality in your applications. This guide covers common testing scenarios and best practices.
Generate unique email addresses in milliseconds. Each test gets its own isolated mailbox, preventing test interference and ensuring reliable results.
No more flaky tests due to email delivery delays. DevInbox provides instant, reliable email capture for consistent test results.
Verify email content, extract structured data, and ensure emails follow your templates with powerful template matching capabilities.
No need for real email services or complex email server setups. Start testing immediately with our generous free tier.
Use the API to generate a unique email address for your test
Execute your application logic that sends the email
Retrieve the message and assert it contains the expected content
import requests def test_user_registration_sends_welcome_email(): API_KEY = "your_api_key" headers = {"X-Api-Key": API_KEY} # Arrange - Create mailbox r = requests.post( "https://api.devinbox.io/mailboxes", headers=headers, json={}) mailbox = r.json() test_email = f"{mailbox['key']}@devinbox.io" # Act - Trigger registration user_service.register( email=test_email, name="John Doe") # Assert - Verify email r = requests.get( f"https://api.devinbox.io/messages/{mailbox['key']}", headers=headers) messages = r.json() assert messages['count'] == 1 assert "Welcome" in messages['messages'][0]['subject']
Use templates to verify email structure and extract specific data points automatically. Templates allow you to parse dynamic values like verification codes, user names, and other parameters.
def test_registration_extracts_verification_code(): # Create mailbox and trigger email mailbox = create_test_mailbox() trigger_user_registration( f"{mailbox['key']}@devinbox.io") # Get message with template parsing r = requests.get( f"https://api.devinbox.io/messages/" f"{mailbox['key']}/user-welcome/single", headers={"X-Api-Key": API_KEY}) parsed = r.json() user_name = parsed['subject']['user_name'] verification_code = parsed['body']['verification_code'] assert user_name == "John Doe" assert verification_code is not None
[Test] public async Task Registration_ExtractsVerificationCode() { // Create mailbox and trigger email var mailbox = await CreateTestMailbox(); await TriggerUserRegistration( $"{mailbox["key"]}@devinbox.io"); // Get message with template parsing var key = mailbox.GetProperty("key").GetString(); var response = await client.GetAsync( $"https://api.devinbox.io/messages/" $"{key}/user-welcome/single"); var json = await response .Content.ReadAsStringAsync(); var parsed = JsonSerializer .Deserialize<JsonElement>(json); var userName = parsed.GetProperty("subject") .GetProperty("user_name").GetString(); var verificationCode = parsed.GetProperty("body") .GetProperty("verification_code").GetString(); Assert.That(userName, Is.EqualTo("John Doe")); Assert.That(verificationCode, Is.Not.Null); }
Test that password reset emails are sent and contain valid reset links.
// Request password reset await authService.RequestPasswordResetAsync(testEmail); // Get the last email var response = await client.GetAsync( $"https://api.devinbox.io/messages/{key}/last"); var json = await response .Content.ReadAsStringAsync(); var email = JsonSerializer .Deserialize<JsonElement>(json); Assert.That(email.GetProperty("subject") .GetString(), Does.Contain("Password Reset")); Assert.That(email.GetProperty("body") .GetString(), Does.Contain("reset-password"));
Verify order confirmation emails contain correct order details.
// Process order var orderId = await orderService.CreateOrderAsync( testEmail, orderItems); // Verify with template var response = await client.GetAsync( $"https://api.devinbox.io/messages/" $"{key}/order-confirmation/last"); var json = await response .Content.ReadAsStringAsync(); var parsed = JsonSerializer .Deserialize<JsonElement>(json); Assert.That(parsed.GetProperty("body") .GetProperty("order_id").GetString(), Is.EqualTo(orderId.ToString()));
Test that notifications are sent to all expected recipients.
// Create multiple test mailboxes var mailboxes = await Task.WhenAll( Enumerable.Range(0, 3) .Select(_ => CreateTestMailbox())); // Trigger notification await notificationService.SendAlertAsync( "System Maintenance"); // Verify all received foreach (var mailbox in mailboxes) { var key = mailbox.GetProperty("key").GetString(); var response = await client.GetAsync( $"https://api.devinbox.io/messages/" $"{key}/count"); var json = await response .Content.ReadAsStringAsync(); var count = JsonSerializer .Deserialize<JsonElement>(json) .GetProperty("count").GetInt32(); Assert.That(count, Is.GreaterThan(0)); }
Always use temporary mailboxes for tests. They're automatically cleaned up about an hour after their last activity and don't count against your persistent mailbox quota.
Check the message count before retrieving messages to ensure your test received
the expected number of emails. Use /messages/{key}/single
when expecting exactly one email.
Create templates for emails with dynamic content. Templates make tests more maintainable and allow you to extract specific values like verification codes or order numbers.
Create a new mailbox for each test to ensure complete isolation. This prevents tests from interfering with each other and makes debugging easier.
DevInbox captures emails instantly, but your application might have some delay before sending. Add small delays or retries if needed, though usually emails arrive immediately.
Store your DevInbox API key securely using environment variables:
# Linux/macOS export DEVINBOX_API_KEY="your_api_key_here" # Windows PowerShell $env:DEVINBOX_API_KEY="your_api_key_here"
Configure an HTTP client once in your test setup for reuse across tests:
[SetUp] public void Setup() { _client = new HttpClient(); _client.DefaultRequestHeaders.Add( "X-Api-Key", Environment.GetEnvironmentVariable( "DEVINBOX_API_KEY")); }
For Python, configure the requests library with default headers in your test fixtures.
Explore our open-source SDKs and contribute to the DevInbox ecosystem on GitHub.
Browse all DevInbox repositories and SDKs on GitHub.
C# client library for the DevInbox API.
Complete Python client generated from OpenAPI specification.
TypeScript/JavaScript SDK for managing test mailboxes.
Java client library for DevInbox API integration.