Alfred Danda - [PHP - Laravel - Vue.js - Running - Music]
Photo by Christin Hume on Unsplash

Using MailHog with Lando

Lando is a very convenient and open source tool for local web development. If you don't know what Lando is, you can read more about it, why it's useful and how to use it in my post How to use Lando for local development with Laravel.

MailHog is another very useful tool for local development if you have to deal with mail. You can define your MailHog installation as an SMTP server and all mails go directly into MailHog where you can see the plain text and HTML versions of the mail and all available headers in a web view.

And best of all: Lando and MailHog work well together. There is a dedicated Lando plugin for MailHog that you can use without much manual configuration.

How to add MailHog to your Lando project

To add MailHog to your Lando project, all you have to do is add it as a service to your project's .lando.yml file. What does that mean exactly? It means that you have to add the MailHog service under the services section in your .lando.yml file and add a proxy entry in the proxy section to access the MailHog instance:

services:
  mailhog:
    type: mailhog
proxy:
  mailhog:
    - mailhog.lndo.site

That's it. After a lando rebuild of your project, MailHog is installed and you can access it by going to mailhog.lndo.site in your browser. You will see your local MailHog instance waiting for your first mails.

You can use any lndo.site subdomain for MailHog that does not conflict with other subdomains you use in your projects. For example, instead of mailhog.lndo.site you can use mail.lndo.site:

services:
  mailhog:
    type: mailhog
proxy:
  mailhog:
    - mail.lndo.site

But how do you tell your application to send mail to MailHog?

How to configure your application to use MailHog

To configure your application to use MailHog, you need to change the mail settings for your application. For a Laravel project, you would typically do this in your .env file. For a Wordpress project, in your wp-config.php file.

Once you have found the mail settings for your project, you need to modify them like this:

host: mailhog
port: 1025
username: null or empty
password: null or empty
encryption: null or empty

For example, for a Laravel application, the settings in the .env file would look like this:

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

That's it, the next mail you send with your application in your local development environment should go straight to MailHog, and you can view the mail by going to the MailHog web view.

If you have any questions about how we use Lando at our company Ideenreich feel free to contact me on Twitter or by mail.

Back to all posts Share on Twitter Share on LinkedIn Share on Reddit