Mailpit is a local email testing tool, similar to MailHog or MailCatcher, used by developers to capture and inspect emails sent by an application during development. It provides a web-based interface where you can view, search, and debug email messages without actually sending them to a live email server.
It is a very useful and developer friendly tool but there is no adequate documentation on how to set it up in a Laravel app. That's what we'll do today.
Basic Setup
- Install Mailpit: You can install it via Homebrew on macOS.
brew install mailpit
If you are on Windows or Linux you can download the static binary. Read this guide for more information.
- Run Mailpit: Start the Mailpit server by running:
mailpit
Or set it up to run automatically by running:
brew services start mailpit
-
Access Mailpit Web Interface:
Open your browser and go to
http://localhost:8025
to view incoming emails in the Mailpit UI.
Laravel Setup
Go to you .env
file and input this setup
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=your username @ your system name here
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
You can get your user and system name by running the following command
echo "$(whoami)@$(hostname)"
That's all! Now whenever an email is sent from your laravel app you would be able to view it in the browser.