Bobcares

Docker Mailhog Sendmail | Set Up Guide

by | Feb 29, 2024

Learn how to set up Docker Mailhog & Sendmail. Our Sendmail Support team is here to help you with your questions and concerns.

Docker Mailhog Sendmail | Set Up Guide

MailHog is a popular open-source email testing tool. It lets developers test the web app’s email-sending and receiving features more efficiently.

In this blog post, we will take a close look at setting up Docker MailHog and Sendmail.

Docker Mailhog Sendmail | Set Up Guide

The process usually involves running MailHog and a Sendmail-compatible service inside Docker containers. This setup lets developers test email functionality within their applications and not worry about emails being sent to real recipients.

How to Set Up Docker MailHog and Sendmail

  1. To begin with, make sure Docker is installed on the system.
  2. Then, we have to create a `docker-compose.yml` file in our project directory with the following content to set up MailHog and a Sendmail-compatible service.

    version: '3'
    services:
    mailhog:
    image: mailhog/mailhog
    ports:
    - "1025:1025" # SMTP port
    - "8025:8025" # MailHog web UI port
    sendmail:
    image: mailhog/sendmail
    environment:
    RELAY_HOST: mailhog:1025 # MailHog SMTP host and port

  3. Now, head to the directory with the `docker-compose.yml` file in a terminal and run the following command to start the Docker containers:

    docker-compose up -d

    This command pulls the required Docker images and starts the MailHog and Sendmail containers in detached mode.

  4. Next, update the application’s email configuration to use the Sendmail service. Typically, set the SMTP server to `localhost` and the port to `25`.
  5. Then, start the application and trigger any functionality that sends emails. MailHog intercepts these emails, and we can view them through the MailHog web UI at http://localhost:8025.
  6. Now, open the MailHog web UI to inspect intercepted emails, including content, headers, and recipients.
  7. After testing, stop the Docker containers with the following command:

    docker-compose down

Configure MailHog with mhsendmail

For more control over email routing, we can use `mhsendmail`. It is a sendmail replacement tailored for MailHog. Follow these steps to configure and use `mhsendmail`:

  1. To begin with, download `mhsendmail` from its GitHub repository.
  2. Then, edit the web app’s configuration to use `mhsendmail` as the email routing service. Most systems default to `sendmail`, so adjust the `sendmail_path` in the `php.ini` file.
    • For Linux systems, set the value to:

      sendmail_path = /usr/local/bin/mhsendmail

    • For Mac users, edit the Postfix config file with:

      myhostname = localhost
      relayhost = [127.0.0.1]:1025

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to set up Docker Mailhog & Sendmail.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.