MailHog

Arun Pandey
2 min readFeb 8, 2022

Introduction

Many developments and testing teams need to fake SMTP server to test email-related functionalities. For such use cases MailHog can be a suitable option.

What is MailHog?

MailHog is an email testing tool for developers:

  • Use MailHog for SMTP delivery
  • Web UI to view messages
  • REST API to fetch the messages
  • It can also relay messages to actual SMTP servers for delivery

Setup

For POC setup is Useing MailHog docker container.

docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog

  • SMTP server starts on port 1025
  • HTTP server starts on port 8025
  • By default MailHog uses in-memory message storage

Web UI — UI provides a way to check sent emails and manage emails.

Email client code -

Test code uses the simple-java-mail framework to connect SMTP service and send an email.

MailerBuilder
.withSMTPServerHost("192.168.1.111")
.withSMTPServerPort(1025)
.buildMailer()
.sendMail(EmailBuilder.startingBlank()
.to("to@demo.com")
.from("from@demo.com")
.withSubject("Demo Subject")
.withHTMLText("Demo Body")
.buildEmail());

Features

  • Very lightweight and portable
  • Easy to configure and run
  • Web UI for checking emails
  • Rest API interface for testing with basic authentication
  • Docker image is available
  • Prebuild Helm chart available for Kubernetes deployment
  • Support for SMTP AUTH (RFC4954) and PIPELINING (RFC2920)
  • Supports RFC2047 encoded headers
  • Relay messages to real SMTP servers
  • Multipart MIME support
  • In-memory message storage
  • Optionally MongoDB and file-based storage for message persistence

Cons

  • Does not provide out of box support for SMPTS (unable to find any documentation for the same)

References

--

--

Arun Pandey

Hands-on Software Architect with extensive experience in developing and supporting mission-critical applications.