I’ll often clone the db from production to staging to reproduce bugs or performance issues. The staging site is not visible to the public, so emails with links to it will confuse/annoy people. Today I accidentally sent emails to people from our staging setup.
To stop this happening again – I’ve a quick monkeypatch to only send emails to recipients in our domain. I placed this in config/environments/staging.rb.
class ActionMailer::Base
def perform_deliveries
@mail.header['to'].to_s =~ /@example.com$/
end
end
Replace example.com with your particular domain