Skip to content

MailHog

Web and API based SMTP testing

WARNING

테스트용으로만 사용한다

Features

See MailHog libraries for a list of MailHog client libraries.

  • ESMTP server implementing RFC5321
  • Support for SMTP AUTH (RFC4954) and PIPELINING (RFC2920)
  • Web interface to view messages (plain text, HTML or source)
    • Supports RFC2047 encoded headers
  • Real-time updates using EventSource
  • Release messages to real SMTP servers
  • Chaos Monkey for failure testing
    • See Introduction to Jim for more information
  • HTTP API to list, retrieve and delete messages
    • See APIv1 and APIv2 documentation for more information
  • HTTP basic authentication for MailHog UI and API
  • Multipart MIME support
  • Download individual MIME parts
  • In-memory message storage
  • MongoDB and file based storage for message persistence
  • Lightweight and portable
  • No installation required

Docker CLI example

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

sendmail Usage:

sendmail -S mail:1025

Configuring MailHog

You can configure MailHog using command line options or environment variables:

Environment

Command line

Default

Description

MH_CORS_ORIGIN

-cors-origin

If set, an Access-Control-Allow-Origin header is returned for API endpoints

MH_HOSTNAME

-hostname

mailhog.example

Hostname to use for EHLO/HELO and message IDs

MH_API_BIND_ADDR

-api-bind-addr

0.0.0.0:8025

Interface and port for HTTP API server to bind to

MH_UI_BIND_ADDR

-ui-bind-addr

0.0.0.0:8025

Interface and port for HTTP UI server to bind to

MH_MAILDIR_PATH

-maildir-path

Maildir path (for maildir storage backend)

MH_MONGO_COLLECTION

-mongo-coll

messages

MongoDB collection name for message storage

MH_MONGO_DB

-mongo-db

mailhog

MongoDB database name for message storage

MH_MONGO_URI

-mongo-uri

127.0.0.1:27017

MongoDB host and port

MH_SMTP_BIND_ADDR

-smtp-bind-addr

0.0.0.0:1025

Interface and port for SMTP server to bind to

MH_STORAGE

-storage

memory

Set message storage: memory / mongodb / maildir

MH_OUTGOING_SMTP

-outgoing-smtp

JSON file defining outgoing SMTP servers

MH_UI_WEB_PATH

-ui-web-path

WebPath under which the UI is served (without leading or trailing slashes), e.g. 'mailhog'

MH_AUTH_FILE

-auth-file

A username:bcryptpw mapping file

Default config

  • the SMTP server starts on port 1025
  • the HTTP server starts on port 8025
  • in-memory message storage

Mailhog with MongoDB in docker-compose.yml

version: '2'

services:
  mail:
    depends_on:
      - mongo
    ports:
      - 1025:1025 # smtp server
      - 8025:8025 # web ui
    environment:
      MH_STORAGE: mongodb
      MH_MONGO_URI: mongo:27017

  mongo:
    image: mongo

Mailhog + WordPress in docker-compose.yml

version: '3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress

   mailhog:
     image: mailhog/mailhog
     ports: 
       - 1025:1025 # smtp server
       - 8025:8025 # web ui

volumes:
    db_data:

functions.php:

<?php
add_action( 'phpmailer_init', 'setup' );
function setup( PHPMailer $phpmailer ) {
    $phpmailer->Host = 'mailhog';
    $phpmailer->Port = 1025;
    $phpmailer->IsSMTP();
}

See also

Favorite site