Get MailCatcher up and running in minutes
MailCatcher NG requires Ruby 3.2 or higher. Ensure you have Ruby installed:
ruby -v
Then install via RubyGems:
gem install mailcatcher-ng
Start the server:
mailcatcher
# View mail at http://127.0.0.1:1080
# Send mail to smtp://127.0.0.1:1025
Run in foreground with custom ports:
MAILCATCHER_ENV=development bundle exec mailcatcher \
--foreground \
--smtp-port 1025 \
--http-port 1080
Add to config/environments/development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: '127.0.0.1',
port: 1025
}
config.action_mailer.raise_delivery_errors = false
Add to settings.py:
if DEBUG:
EMAIL_HOST = '127.0.0.1'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 1025
EMAIL_USE_TLS = False
Update .env:
MAIL_MAILER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Update php.ini sendmail path:
sendmail_path = /usr/bin/env catchmail -f from@example.com
Run MailCatcher with the official Alpine Linux image:
docker run -d -p 1080:1080 -p 1025:1025 stpaquet/alpinemailcatcher
Then access the web interface at http://127.0.0.1:1080 and send mail to smtp://127.0.0.1:1025
View the image on Docker Hub
mailcatcher ng --help
Options:
--ip IP Set IP address for both servers
--smtp-ip IP Set SMTP server IP
--smtp-port PORT Set SMTP port (default: 1025)
--smtp-ssl Enable SSL/TLS support for SMTP
--smtp-ssl-cert PATH Path to SSL certificate file
--smtp-ssl-key PATH Path to SSL private key file
--smtp-ssl-verify-peer Verify client SSL certificates
--smtps-port PORT Direct TLS port (default: 1465)
--http-ip IP Set HTTP server IP
--http-port PORT Set HTTP port (default: 1080)
--messages-limit COUNT Keep only N most recent messages
--persistence Store messages in a persistent SQLite database file
--http-path PATH Add prefix to all HTTP paths
--no-quit Disable quit functionality
-f, --foreground Run in foreground
-b, --browse Open web browser on start
-v, --verbose Be more verbose
-h, --help Show this help
--version Show version
By default, MailCatcher NG stores messages in memory and they are lost when the process terminates. Enable persistent storage to keep messages across restarts:
mailcatcher --persistence
Messages will be stored in a SQLite database file at ~/.mailcatcher/mailcatcher.db
When using Docker, you need to mount a volume to persist the database file. Note: The current Docker image does not yet include support for the --persistence flag. This feature will be added in a future release.
docker run -d \
-p 1080:1080 \
-p 1025:1025 \
-v mailcatcher_data:/root/.mailcatcher \
stpaquet/alpinemailcatcher
Or with a bind mount to a host directory:
docker run -d \
-p 1080:1080 \
-p 1025:1025 \
-v /path/to/local/storage:/root/.mailcatcher \
stpaquet/alpinemailcatcher
MailCatcher supports encrypted SMTP connections using SSL/TLS. You must provide your own certificate and private key files.
openssl req -x509 -newkey rsa:4096 \
-keyout mailcatcher-key.pem \
-out mailcatcher-cert.pem \
-days 365 -nodes \
-subj "/CN=localhost"
mailcatcher \
--smtp-ssl \
--smtp-ssl-cert mailcatcher-cert.pem \
--smtp-ssl-key mailcatcher-key.pem
This enables:
config.action_mailer.smtp_settings = {
address: '127.0.0.1',
port: 1025,
enable_starttls_auto: true
}
config.action_mailer.smtp_settings = {
address: '127.0.0.1',
port: 1465,
enable_starttls_auto: false,
ssl: true
}
if DEBUG:
EMAIL_HOST = '127.0.0.1'
EMAIL_PORT = 1465 # Direct TLS
EMAIL_USE_TLS = True
EMAIL_USE_SSL = True
MAIL_PORT=1465
MAIL_ENCRYPTION=ssl # or 'tls' for STARTTLS on port 1025
For production-like testing, use certificates from your CA or Let's Encrypt:
mailcatcher \
--smtp-ssl \
--smtp-ssl-cert /etc/ssl/certs/your-cert.pem \
--smtp-ssl-key /etc/ssl/private/your-key.pem \
--smtp-ssl-verify-peer
Use different ports:
mailcatcher --smtp-port 2025 --http-port 2080
Ensure Ruby 3.2+ is installed:
brew install ruby # macOS
apt install ruby # Ubuntu/Debian
Install build tools for gem compilation:
apt install build-essential # Ubuntu/Debian
xcode-select --install # macOS
MailCatcher may only be available in the Ruby version it was installed in:
rvm default@mailcatcher --create do gem install mailcatcher
ln -s "$(rvm default@mailcatcher do rvm wrapper show mailcatcher)" "$rvm_bin_path/"
git clone https://github.com/spaquet/mailcatcher.git
cd mailcatcher
bundle install
bundle exec rake package
gem install mailcatcher-ng-VERSION.gem