Installing Mailcatcher for use in Laravel Projects

Installing Mailcatcher for use in Laravel Projects

Using Laravel Homestead is an excellent way to quickly create and maintain Laravel projects. At some point you will want to test out your emails, this could be a registration email or a newsletter. Either way you will want somewhere locally to receive and test each time. MailCatcher is run on your local browser using the address, http://localhost:1080.

Let’s Begin

Make sure Vagrant is down by running
vagrant halt
We need to set up our homestead.rb file with some port forwarding rules. You can find this in homestead/scripts/homestead.rb. Add the following line to this file in the default_ports
1080 => 1080
.Once this is saved run:
vagrant up
. You will notice in the processes and forwarded port defaultL 1080=>1080(adapter 1). Now SSH into Vagrant using in your homestead folder:
vagrant ssh
Run:
sudo apt-get update
sudo apt-get install ruby1.9.1-dev
sudo gem install mailcatcher
To ensure this runs on vagrant up everytime create a new file called:
sudo nano /etc/init/mailcatcher.conf
#In this file save this
description "Mailcatcher"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/bin/env $(which mailcatcher) --foreground --http-ip=0.0.0.0
Now exit the Vagrant Box and run:
vagrant reload
In your Laravel Project you need to go into you .env file and set this:
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
You should now recieve emails on http://localhost:1080

Categories: Posts