Skip to content

MailHog

Part of the Sidecar Services catalog.

What it does

MailHog is a mail catcher. It accepts SMTP from WordPress and holds every message in a web inbox instead of delivering it, so outbound mail (password resets, form notifications, WooCommerce receipts) is captured locally and nothing is sent for real. Add it when you want to inspect the mail a project sends without risking delivery to actual recipients.

MailHog and Mailpit do the same job. MailHog is the older, no-longer-actively-maintained option; prefer Mailpit for new work unless a project specifically expects MailHog.

How it works

The preset pins mailhog/mailhog:v1.0.1. The web inbox runs on container port 8025 and SMTP is accepted on 1025. Caught mail is not persisted to a volume, so the inbox is cleared when the container is recreated.

MailHog gets a browser UI on port 8025: the host port is auto-allocated from the 7000 to 7999 range and de-conflicted across all projects.

bash
wdg my-site service add mailhog
wdg my-site service list

Read the inbox URL from the service list output.

How it integrates with the local WordPress container

Adding the sidecar injects these env vars into the WordPress container:

VariableValue
WORDPRESS_SMTP_HOSTwdg-my-site-mailhog (the @HOST token resolved at add-time)
WORDPRESS_SMTP_PORT1025

The injected env points WordPress at the SMTP endpoint, not the inbox UI. WordPress reaches MailHog over wdg-network at wdg-my-site-mailhog:1025, never the host port. The host port serves the browser inbox only.

These env vars are connectivity hints. The project still routes wp_mail() through SMTP. With an SMTP plugin, or a small mu-plugin on phpmailer_init, read the injected host and port and use no authentication:

php
add_action( 'phpmailer_init', function ( $phpmailer ) {
	$phpmailer->isSMTP();
	$phpmailer->Host       = getenv( 'WORDPRESS_SMTP_HOST' ); // wdg-my-site-mailhog
	$phpmailer->Port       = (int) getenv( 'WORDPRESS_SMTP_PORT' ); // 1025
	$phpmailer->SMTPAuth   = false;
	$phpmailer->SMTPSecure = '';
} );

Adding the sidecar wires reachability only. The project still configures WordPress to send over SMTP.

Add and remove

bash
wdg my-site service add mailhog
wdg my-site service remove mailhog  # no data volume to keep; --purge is a no-op here