Define email patterns with placeholders to verify structure and extract dynamic data from your application's emails. Templates make integration tests more reliable and maintainable.
{{UserName}}
to mark dynamic content. When you verify an email against a template, DevInbox automatically
extracts these values for assertion in your tests.
Ensure emails follow the expected format and contain all required elements in the correct order.
Pull out dynamic values like verification codes, user names, or order numbers for validation.
Write cleaner tests that focus on the data that matters, not fragile string matching.
Templates use double curly braces {{}}
to define placeholders for dynamic content. The parser extracts values that match these placeholders
when verifying an email.
Subject: Welcome to {{CompanyName}}, {{UserName}}! Body: Hello {{UserName}}, Welcome to {{CompanyName}}! Your verification code is: {{VerificationCode}} Best regards, The {{CompanyName}} Team
When you verify an email against a template, DevInbox's template parser:
Welcome {{UserName}}! Code: {{Code}}
Welcome John Doe! Code: ABC123
Extracted:
UserName = "John Doe"
Code = "ABC123"
A common template for welcome emails sent during user registration.
Template Name: user-welcome Subject Pattern: Welcome to {{CompanyName}}, {{UserName}}! Body Pattern: Hello {{UserName}}, Welcome to {{CompanyName}}! Your account has been created successfully. Verification Code: {{VerificationCode}} Best regards, The {{CompanyName}} Team
Template for password reset requests with time-sensitive links.
Template Name: password-reset Subject Pattern: Password Reset Request for {{UserName}} Body Pattern: Hello {{UserName}}, You requested a password reset. Click the link below: {{ResetLink}} This link expires in {{ExpiryHours}} hours.
Template for e-commerce order confirmations with order details.
Template Name: order-confirmation Subject Pattern: Order #{{OrderNumber}} Confirmation Body Pattern: Thank you for your order, {{CustomerName}}! Order Number: {{OrderNumber}} Total: ${{Total}} We'll send you tracking information once shipped.
Use the endpoint /messages/{key}/{template}/single
to retrieve and parse the most recent email matching your template. The API returns extracted values
ready for assertions in your tests.
import requests def test_welcome_email_with_template(): API_KEY = "your_api_key" headers = {"X-Api-Key": API_KEY} # Create mailbox r = requests.post( "https://api.devinbox.io/mailboxes", headers=headers, json={}) mailbox = r.json() test_email = f"{mailbox['key']}@devinbox.io" # Trigger registration user_service.register( email=test_email, name="Jane Smith", company="Acme Corp") # Get parsed email using template r = requests.get( f"https://api.devinbox.io/messages/" f"{mailbox['key']}/user-welcome/single", headers=headers) parsed = r.json() # Extract and verify template values assert parsed['subject']['UserName'] == "Jane Smith" assert parsed['subject']['CompanyName'] == "Acme Corp" assert parsed['body']['VerificationCode'] is not None assert len(parsed['body']['VerificationCode']) == 6
Start with basic templates that capture essential fields. Avoid overly complex patterns that might break with minor formatting changes in your emails.
Choose clear variable names that match your application's domain. Use
{{VerificationCode}} instead of
{{Code}} for clarity.
Before using templates in your tests, verify they correctly match real emails from your application using the DevInbox dashboard or API.
The template parser normalizes line endings but respects spacing. Be mindful of whitespace in your patterns, especially around placeholders.
Keep your template definitions in your repository alongside your tests. This ensures templates evolve with your application and are accessible to all team members.
Templates support multi-line patterns. The parser normalizes line endings, so your templates work consistently across different email formats.
Hello {{Name}},\n\nYour code is {{Code}}
The template parser uses non-greedy matching for placeholders. If you have multiple placeholders in sequence, each captures the minimum text needed to satisfy the pattern.
When your email format changes, create new template versions rather than updating existing ones. This prevents old tests from breaking unexpectedly.
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.