Capture emails on staging?

I like the way the mailhog is set up on development by default to capture any mails sent by the server. I feel that staging needs a similar capture setup. If we copy the db from production to staging (or vice versa) we don’t want every user of the website getting the same email twice.

I can see two solutions:

  1. add mailhog to staging
  2. give staging different smtp details to production

However, in both cases, staging is no longer identical to production, which isn’t ideal.

Personally I would go with 2, but Trellis uses the same smtp details for both staging and production, which suggests to me that having 2 sets of details should be avoided.

Is there another way? It seems you would need a transactional mail service that allowed you to capture emails based on a rule (source IP address?) but let everything else through. Does anyone know of a service with this feature? Or have any other ideas for a solution?

I don’t know of any service that provides email capturing but I’d still probably go with the 2nd solution.

Trellis does let you have different credentials for staging/production. Right now it’s just under group_vars/all for convenience. You can just move/duplicate that file to group_vars/staging/mail.yml and group_vars/production/mail.yml


assuming you’re catching/suppressing emails going out from your staging server – what SMTP details/email service did you go with?

For staging I tend to use a free account from

I have all my trellis sites pointed at the same free mailbox, which has a limit of 50 emails (above that it deletes the old mails). Mostly fine for staging, as you often just need to check that a recent email was sent successfully.