MailCatcher is a tool that provides an easy way for developers to inspect emails that their applications send out without having to wait for an email provider. It catches all emails that it receives, and stores them for display. Both HTML and plain text messages are supported.
# Update repositories sudo apt-get update # Install Basics # build-essential needed for "make" command sudo apt-get install -y build-essential software-properties-common \ vim curl wget tmux # Install PHP 5.6 sudo add-apt-repository -y ppa:ondrej/php sudo apt-get update sudo apt-get install -y php5.6-cli php5.6-fpm php5.6-mcrypt php5.6-curl # Install Mailcatcher Dependencies (sqlite, ruby) sudo apt-get install -y libsqlite3-dev ruby2.3-dev
And then let’s install Mailcatcher .
# Install Mailcatcher as a Ruby gem sudo gem install mailcatcher
Setup relay on postfix settings.
# Add relay host port relayhost = 127.0.0.1:1025
service postfix restart
Once that’s installed, we can see the available options:
$ mailcatcher --help Usage: mailcatcher [options] --ip IP Set the ip address of both servers --smtp-ip IP Set the ip address of the smtp server --smtp-port PORT Set the port of the smtp server --http-ip IP Set the ip address of the http server --http-port PORT Set the port address of the http server -f, --foreground Run in the foreground -v, --verbose Be more verbose -h, --help Display this help information
Then we can can start using Mailcatcher. We’ll bind the web interface’s IP address to all networks:
mailcatcher --foreground --http-ip=0.0.0.0
This will run Mailcatcher in the foreground. You can exit it by hitting Ctrl+C.
Start on Boot
It is useful to setup Mailcatcher to start when the server boots. This lets us forget about having to turn on Mailcatcher whenever we start our development machine.
Rather than install a process monitor, we can use Upstart, which currently comes out of the box with Ubuntu. This will get replaced with Systemd eventually. For now, we can use Upstart.
Create and edit file
description "Mailcatcher" start on runlevel  stop on runlevel [!2345] respawn exec /usr/bin/env $(which mailcatcher) --foreground --http-ip=0.0.0.0
Let’s cover what this Upstart configuration is doing.
This configuration file tells Upstart to start Mailcatcher at runlevel 2,3,4 and 5.
Our configuration says to start when the above runlevels are reached and stop when the runlevels are absent.
respawn directive tells Upstart to restart Mailcatcher if it fails.
Finally we set the command to start Mailcatcher. I used
/usr/bin/env to find the environment’s location of
mailcatcher. This is useful as the location may change if Mailcatcher was installed using RVM or another environment manager for Ruby.
We configure Mailcatcher to run in the foreground with the
--foreground option. Mailcatcher daemonizes by default. However, Upstart either needs to be told to
expect daemon or to run the process in the foreground. The latter is simpler.
sudo service mailcatcher status sudo service mailcatcher start sudo service mailcatcher restart sudo service mailcatcher stop
sudo service mailcatcher start to kick it off.
Then you can head to the server’s IP address at port
1080 to see the web interface!