Docker Compose

Hand the sandbox credentials to a service as environment variables — no container to run alongside it.

1Set the variables on the service

docker-compose.yml
# docker-compose.yml
services:
  app:
    environment:
      SMTP_HOST: smtp.mailclutch.com
      SMTP_PORT: "587"
      SMTP_USER: mc_0000000000000000
      SMTP_PASSWORD: pw_0000000000000000

Use the names your application already reads — MAIL_HOST for Laravel, EMAIL_HOST for Django, and so on.

2Or keep them in an env file

.env
# .env — next to docker-compose.yml
SMTP_HOST=smtp.mailclutch.com
SMTP_PORT=587
SMTP_USER=mc_0000000000000000
SMTP_PASSWORD=pw_0000000000000000
services:
  app:
    env_file: .env

Watch it land

Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.

Nothing is ever delivered onward, whatever address you send to; claim the inbox with an account and it stays.

Awaiting your email

Send from any address; it stops here rather than going onward. The inbox keeps what it catches for 24 hours.

What usually goes wrong

  • Replacing MailHog or Mailpit

    Drop the mail container from the file and point the same variables here. The inbox moves off the machine, and everyone on the team looks at the same one.

  • Outbound ports

    A container reaches the sandbox over the host's network. If the host blocks 25 and 587, use 2525.

Official documentationDocker — environment variables (opens in a new tab)