Stop your staging site emailing real customers
Short answer: A staging or test copy of your site usually starts life as a copy of the live one, including real customer email addresses and a working email connection. The moment a scheduled job or test order runs, real customers get reminders, invoices or "your order has shipped" messages that aren't real. Point every non-production copy at a mail catcher, a fake mail server such as Mailpit that captures messages so you can view them in a browser without sending anything, and add a second safeguard in your app so that even if the mail settings are wrong, outgoing email only goes to your own team.
How it happens
Common routes:
- A database copy from live to staging brings real customers and pending orders with it.
- Scheduled jobs such as abandoned-basket emails, appointment reminders or renewal notices run on staging just as they do on live, working through real addresses.
- The same email credentials are in both environments, because the config was copied too.
- A developer tests the checkout with a customer's account to reproduce a bug.
- Bulk actions in an admin screen, like "resend invoices", are tried out on staging.
From the customer's side, it looks like your business made a mistake or was hacked. Some will reply, some will pay a duplicate invoice, and some will lose trust in your real emails.
Safeguard 1: a mail catcher
A mail catcher pretends to be an SMTP server. Your app sends email as usual, but nothing leaves; messages are stored and shown in a web inbox.
Mailpit, for example, describes itself as an email testing tool that acts as an SMTP server, provides a web interface to view captured emails, and offers an API for automated tests. It also includes an HTML compatibility checker, a link checker and spam testing, which makes it useful for reviewing templates, not just stopping leaks.
Set staging and local environments to send through the catcher's SMTP address instead of your real email provider. Developers see every email the app would have sent, with full content, and no customer receives anything.
Safeguard 2: environment-specific mail settings
Most frameworks let you choose the email delivery method per environment. Django's documentation, for example, describes a console backend that writes emails to the terminal instead of sending them, and an in-memory backend that stores them for tests, both intended for development. WordPress, Laravel, Rails and others have similar options or plugins.
The rule: production credentials for your email provider should exist only in production. If staging doesn't have the key, it can't send real email even by accident.
Safeguard 3: an allowlist in the app
As a last line of defence, add a small check in your app's email code for non-production environments: if the recipient isn't on your team's domain or an allowlist, rewrite it to a team inbox or drop it, and add "[STAGING]" to the subject. This catches the cases where someone points staging at a real provider to test deliverability.
Test the safeguards
After setting this up, prove it works. On staging, place a test order with an outside address you control, run each scheduled job once, and trigger a password reset. Every message should appear in the mail catcher and none in the outside inbox. Repeat the check after any change to environment settings, hosting or the email library, because those are exactly the moments when a production setting quietly comes back.
Don't forget other channels
The same problem applies to:
- SMS reminders and verification codes, which may also cost money per message
- Push notifications to real devices registered in a copied database
- Webhooks to partners, such as sending test orders to your warehouse or accounting system
- Payment actions, if staging has live payment keys instead of test keys
Use test or sandbox modes for each, and keep live keys out of non-production config.
Make copies safer from the start
When you refresh staging from live, change customer email addresses and phone numbers as part of the copy, for example to customer-1234@example.test. Pause scheduled jobs on staging by default and switch on only the ones you're testing. Document the refresh steps so they happen the same way every time.
If it already happened
- Stop the source: disable outgoing mail on staging and pause its scheduled jobs.
- Find out exactly which messages went to whom, using your email provider's logs.
- Send a short, plain apology to affected customers explaining the message was sent in error and what, if anything, they need to do. Be especially clear if invoices or payment requests went out.
- If personal data was sent to the wrong person, check the rules that apply to you about recording or reporting it.
- Add the safeguards above before staging is used again.
A worked example
An illustrative Brighton florist's developer refreshed the staging site from the live database to test a new subscription feature. Overnight, staging's renewal job emailed dozens of customers that their subscriptions had renewed. The developer disabled the job, used the email provider's log to list recipients, and the owner sent an apology the next morning. Afterwards, staging was pointed at Mailpit, customer addresses were rewritten during every refresh, and the email code refused to send outside the business's domain in any environment except production.
FAQ
Can't I just remember not to run emails on staging?
Scheduled jobs and other people don't remember for you. Make it impossible rather than relying on care.
Do I need a mail catcher for local development too?
Yes. Local copies often use real data and run the same jobs.
Is a catch-all address on my domain good enough?
It works, but a catcher is safer because nothing leaves the machine and it's easier to inspect.
Will this stop me testing deliverability?
Test deliverability separately, from production or with a dedicated test account, not from a staging copy full of customer data.
If your test or staging setup has access to real customers, tell us how it's built and we'll help you lock it down.