Back to Mailhog

CONFIG

docs/CONFIG.md

1.0.12.9 KB
Original Source

Configuring MailHog

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

EnvironmentCommand lineDefaultDescription
MH_CORS_ORIGIN-cors-originIf set, an Access-Control-Allow-Origin header is returned for API endpoints
MH_HOSTNAME-hostnamemailhog.exampleHostname to use for EHLO/HELO and message IDs
MH_API_BIND_ADDR-api-bind-addr0.0.0.0:8025Interface and port for HTTP API server to bind to
MH_UI_BIND_ADDR-ui-bind-addr0.0.0.0:8025Interface and port for HTTP UI server to bind to
MH_MAILDIR_PATH-maildir-pathMaildir path (for maildir storage backend)
MH_MONGO_COLLECTION-mongo-collmessagesMongoDB collection name for message storage
MH_MONGO_DB-mongo-dbmailhogMongoDB database name for message storage
MH_MONGO_URI-mongo-uri127.0.0.1:27017MongoDB host and port
MH_SMTP_BIND_ADDR-smtp-bind-addr0.0.0.0:1025Interface and port for SMTP server to bind to
MH_STORAGE-storagememorySet message storage: memory / mongodb / maildir
MH_OUTGOING_SMTP-outgoing-smtpJSON file defining outgoing SMTP servers
MH_UI_WEB_PATH-ui-web-pathWebPath under which the UI is served (without leading or trailing slashes), e.g. 'mailhog'
MH_AUTH_FILE-auth-fileA username:bcryptpw mapping file

Note on HTTP bind addresses

If api-bind-addr and ui-bind-addr are identical, a single listener will be used allowing both to co-exist on one port.

The values must match in a string comparison. Resolving to the same host and port combination isn't enough.

Outgoing SMTP configuration

Outgoing SMTP servers can be set in web UI when releasing a message, and can be temporarily persisted for later use in the same session.

To make outgoing SMTP servers permanently available, create a JSON file with the following structure, and set MH_OUTGOING_SMTP or -outgoing-smtp.

json
{
    "server name": {
        "name": "server name",
        "host": "...",
        "port": "587",
        "email": "...",
        "username": "...",
        "password": "...",
        "mechanism": "PLAIN"
    }
}

Only name, host and port are required.

mechanism can be PLAIN or CRAM-MD5.

Firewalls and proxies

If you have MailHog behind a firewall, you'll need ports 8025 and 1025 by default.

You can override this using -api-bind-addr, -ui-bind-addr and -smtp-bind-addr configuration options.

If you're using MailHog behind a reverse proxy, e.g. nginx, make sure WebSocket connections are also supported and configured - see this issue for information.