Joeri Verdeyen bio photo

Joeri Verdeyen

Web-engineer, cyclist, Nespresso lover, Strava pusher.

Twitter LinkedIn Instagram Github Stackoverflow Last.fm Strava

Configure MailCatcher for Symfony2

Using MailCatcher in combination with Symfony2 on your development machine will make it easy to check the e-mails you are sending out.

What is MailCatcher

MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface.

Install MailCatcher

Install MailCatcher dependecies, sqlite and ruby.

sudo apt-get install -y libsqlite3-dev ruby1.9.1-dev

Install the MailCatcher Ruby gem

sudo gem install mailcatcher

Start MailCatcher

mailcatcher --foreground --http-ip=0.0.0.0

This will start up MailCatcher, but only when you trigger this command. I thinks it’s more convenient to start MailCatcher with Upstart.

Create an upstart script

Create and edit file /etc/init/mailcatcher.conf.

description "Mailcatcher"

start on runlevel [2345]
stop on runlevel [!2345]
respawn

pre-start script

bash << "EOF"
  mkdir -p /var/log/mailcatcher
  chown -R vagrant /var/log/mailcatcher
EOF

end script

exec /usr/bin/env $(which mailcatcher) --foreground --http-ip=0.0.0.0 &>>/var/log/mailcatcher/mailcatcher.log

After configuring this upstart config file, you’re able to use the following set of commands:

sudo service mailcatcher status
sudo service mailcatcher start
sudo service mailcatcher restart
sudo service mailcatcher stop

Run sudo service mailcatcher start after that you should be able to visit the web interface on http://10.0.0.2:1080 (replace 10.0.0.2 with the ip of your development machine).

Configure Symfony2

In order to re-route all mail traffic from Swiftmailer to MailCatcher, you should adjust your config_dev.yml file with the following settings:

swiftmailer:
    transport: smtp
    host: 'localhost'
    port: 1025
    username: null
    password: null

And Symfony2 profiler’ mail item?

Yes, that’s still working and for me personal this is a much faster way to check and validate emails and their content.

Thanks for reading

Feel free to leave a comment if you have remarks or like this post