How to Use MailHog to Test Emails Locally (Step-by-Step Guide)

Mailhog

Testing emails in a local development environment can be challenging. It’s a real pain to know whether your website’s or web app’s outgoing emails are actually reaching the recipient’s inbox. Enter, MailHog!

MailHog is an email testing tool that makes it super easy to install and configure a local email server. MailHog sets up a fake SMTP server. You can configure your preferred web applications to use MailHog’s SMTP server to send and receive emails.

For instance, you can configure a local WordPress site to use MailHog for email deliveries. That’s exactly what DevKinsta does to power its built-in SMTP server for testing emails locally.

In this article,  you’ll learn the ins and outs of MailHog, including its installation, configuration, how to test emails locally, and much more!

Ready to dive in? Let’s go!

Want to simplify local email testing? Get MailHog ? Learn how to deploy it easily on various platforms/configurations right here ?Click to Tweet

What is MailHog?

MailHog Web UI

MailHog is an open source email testing tool primarily aimed at developers. It enables you to test your web app’s email sending and receiving capabilities more efficiently.

Built with the Go programming language, MailHog can be run on multiple operating systems, including Windows, Linux, FreeBSD, and macOS. MailHog is maintained by Ian Kent and released under the MIT license, so you can deploy it freely for personal and commercial uses.

But why do you even need MailHog in the first place?

Why You Need MailHog

MailHog solves many of email testing’s major problems.

Say you’re developing a WordPress website in a local development environment. If you want to test a contact form or any other outgoing email from it, it can be a dire task.

Typically, the web application’s default SMTP server takes care of this task. In a local development environment, it almost always never works due to multiple reasons.

You can read our extensive guide on free SMTP servers to know more about how an SMTP server works.

How an SMTP server works (Source: Wikimedia Commons)

How an SMTP server works (Source: Wikimedia Commons)

First, you need to set up your operating system, webserver, and web app to enable emails in a local environment. Then you’ll have to make sure that the emails arrive successfully in your recipient’s inbox, which can end up wasting your time (and inbox space).

And then there’s the issue of using a real email address for testing. It can hurt your private email’s credibility.

MailHog solves all the above issues. It sets up a fake SMTP server that you can set your web application to send and receive emails. It even stores the sent and received emails in a nifty web

[…]

 



This article was written by Salman Ravoof and originally published on Blog – Kinsta.

Disclosure: Some of the links in this post are "affiliate links." This means if you click on the link and purchase the product, We may receive an affiliate commission.

Leave a Comment

You have to agree to the comment policy.

Scroll to Top