What Is an SMTP Sandbox? How It Works and Why Developers Use One
An SMTP sandbox is a mail server that accepts outgoing emails from your application but does not deliver them to real recipients. Instead, it captures every message and makes it available for inspection. The emails are stored safely where developers can view the rendered HTML, read headers, download attachments, and verify content β without any risk of messages reaching actual users.
SMTP sandboxes solve a fundamental problem in software development: you need to test email functionality, but you cannot safely send test emails to real addresses. A misconfigured staging environment, a seeded database with production email addresses, or a developer testing with their own Gmail account can all result in real people receiving test emails. An SMTP sandbox eliminates this risk entirely.
How an SMTP Sandbox Works
From your application's perspective, an SMTP sandbox behaves like any other SMTP server. You configure your application with the sandbox's host, port, and credentials β the same fields you would configure for any mail provider:
MAIL_MAILER=smtp
MAIL_HOST=sandbox.sendpit.com
MAIL_PORT=587
MAIL_USERNAME=your-mailbox-credentials
MAIL_PASSWORD=your-mailbox-password
MAIL_ENCRYPTION=tls
When your application sends an email, it connects to the sandbox using standard SMTP, authenticates, and transmits the message. The sandbox accepts the message with a 250 OK response β exactly like a production mail server would. But instead of routing the message to the recipient's mail server, the sandbox stores it for inspection.
This means your application code does not need any changes. The same Mailables, Notifications, SMTP libraries, and templates you use in production work identically with a sandbox. The only difference is the SMTP configuration.
What You Can Inspect
A good SMTP sandbox captures the complete email and lets you inspect every part of it:
| Component | What It Shows |
|---|---|
| HTML body | The rendered email as a recipient would see it |
| Plain text body | The text/plain alternative for clients that prefer it |
| Headers | From, To, CC, BCC, Reply-To, Subject, Message-ID, and all custom headers |
| Raw source | The complete MIME structure including boundaries and encoding |
| Attachments | File name, MIME type, size, with download and preview |
| TLS status | Whether the connection used encryption |
| Envelope data | The SMTP envelope sender and recipients (may differ from headers) |
This level of inspection is not possible with other testing approaches. Sending to your personal inbox shows you the rendered email but not the raw headers or MIME structure. Using a log driver shows you text but not the rendered HTML. Disabling email delivery shows you nothing at all.
Cloud-Hosted vs Self-Hosted Sandboxes
There are two categories of SMTP sandbox:
Cloud-Hosted Sandboxes
Cloud sandboxes run as managed services. You sign up, get SMTP credentials, and start capturing emails immediately. Examples include SendPit and Mailtrap.
Advantages:
- No infrastructure to manage
- Team members can access captured emails from anywhere
- Works in any environment (local, staging, CI/CD) without additional setup
- Includes features like webhooks, API access, and team collaboration
Best for: Teams, staging environments, CI/CD pipelines, and anyone who wants to start testing in under two minutes.
Self-Hosted Sandboxes
Self-hosted sandboxes run on your own infrastructure, typically as a Docker container. Examples include Mailpit and MailHog (discontinued in 2020).
Advantages:
- Free and open source
- Data stays on your network
- No external dependencies
Limitations:
- Requires Docker or a server to run
- No built-in team access (single-user by default)
- Not accessible from CI/CD without additional networking
- You are responsible for updates and maintenance
Best for: Solo developers working locally, air-gapped environments, or teams that require all data to remain on-premise.
Pricing Comparison
| Sandbox | Type | Free Tier | Paid From |
|---|---|---|---|
| SendPit | Cloud | 100 emails/month, 1 mailbox | $5/month |
| Mailtrap | Cloud | 100 emails/month | $14.99/month |
| Mailpit | Self-hosted | Unlimited | Free (OSS) |
| MailHog | Self-hosted | Unlimited | Free (OSS, unmaintained since 2020) |
When to Use an SMTP Sandbox
During Development
Every developer on your team should send emails through a sandbox during local development. This prevents accidental sends to real addresses and gives everyone a shared view of what the application is sending.
Configure your .env.local or development environment to point at a sandbox. Every email your application sends β signup confirmations, password resets, order notifications β gets captured safely.
In Staging Environments
Staging environments often use production-like data, which may include real email addresses. Without a sandbox, a staging deployment can email actual customers. An SMTP sandbox makes this structurally impossible.
In CI/CD Pipelines
Automated tests can verify that emails are sent with correct content by sending through a sandbox and then querying its API:
// Send email through sandbox
Mail::to('[email protected]')->send(new WelcomeEmail($user));
// Verify via API
$response = Http::get('https://api.sendpit.com/v1/emails', [
'to' => '[email protected]',
]);
expect($response->json('data.0.subject'))
->toContain('Welcome');
This approach tests the full SMTP pipeline β not just that Mail::fake() recorded a dispatch, but that the email was actually transmitted and received.
For QA Reviews
QA engineers can inspect captured emails visually without needing backend access or SMTP credentials. They see the rendered HTML, can check links, verify dynamic content, and flag issues directly.
SMTP Sandbox vs Other Testing Approaches
| Approach | Sees rendered HTML | Inspects headers | Tests SMTP pipeline | Safe from accidental sends | Team access |
|---|---|---|---|---|---|
| SMTP sandbox | Yes | Yes | Yes | Yes | Yes (cloud) |
Mail::fake() |
No | No | No | Yes | N/A |
| Log driver | No (raw text) | Partial | No | Yes | No |
| Personal inbox | Yes | Limited | Yes | No | No |
| Disabling email | No | No | No | Yes | N/A |
An SMTP sandbox is the only approach that tests the full pipeline while remaining safe from accidental sends and providing team visibility.
Setting Up SendPit as Your SMTP Sandbox
- Create a free account at sendpit.com. No credit card required.
- Create a mailbox β this gives you a unique set of SMTP credentials.
- Update your application's SMTP configuration with the mailbox credentials.
- Send a test email from your application. It appears in your SendPit inbox within seconds.
- Invite your team β everyone can view captured emails, inspect headers, and share links to specific messages.
The entire setup takes under two minutes. Your application sends email using standard SMTP, and SendPit captures everything for inspection.
Framework Configuration Examples
Laravel
MAIL_MAILER=smtp
MAIL_HOST=sandbox.sendpit.com
MAIL_PORT=587
MAIL_USERNAME=mb_your_username
MAIL_PASSWORD=your_32_char_password
MAIL_ENCRYPTION=tls
Django
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "sandbox.sendpit.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = "mb_your_username"
EMAIL_HOST_PASSWORD = "your_32_char_password"
Node.js (Nodemailer)
const transporter = nodemailer.createTransport({
host: "sandbox.sendpit.com",
port: 587,
secure: false,
auth: {
user: "mb_your_username",
pass: "your_32_char_password",
},
});
Ruby on Rails
config.action_mailer.smtp_settings = {
address: "sandbox.sendpit.com",
port: 587,
user_name: "mb_your_username",
password: "your_32_char_password",
authentication: :plain,
enable_starttls_auto: true,
}
Summary
An SMTP sandbox captures outgoing emails without delivering them to real recipients. It is the safest and most complete way to test email functionality during development, staging, and CI/CD. Cloud-hosted sandboxes like SendPit provide instant setup, team collaboration, and API access. Self-hosted options like Mailpit are free but require your own infrastructure.
If your application sends email β and nearly every application does β an SMTP sandbox should be part of your development workflow. It takes two minutes to set up and prevents an entire category of production bugs.
Nikhil Rao
Creator of SendPit. Building developer tools for email testing and SMTP infrastructure.
About SendPit →