Setting Up MailDev: A Local Mail Server with Docker

Setting Up MailDev: A Local Mail Server with Docker

Takahiro Iwasa
Takahiro Iwasa
2 min read
MailDev

Introduction

When developing an application, MailDev is an excellent tool for sending and receiving emails within your local environment. This guide walks you through setting up MailDev using Docker and provides instructions for testing email functionality.

Setting Up MailDev with Docker

Step 1: Create a Dockerfile

Create a Dockerfile using the example below.

FROM node:14-alpine
EXPOSE 1080
EXPOSE 1025
RUN npm i -g maildev
CMD ["maildev"]

MailDev uses two ports:

  • 1080 for the management console.
  • 1025 for SMTP.

These ports can be customized using options.

Step 2: Create a Docker Compose Configuration

Create a docker-compose.yml file with the following content:

version: '3'
services:
  mail:
    container_name: mail
    build: ./
    ports:
      - "1080:1080"
      - "1025:1025"

Step 3: Launch the Docker Container

Run the Docker container using the command below:

docker-compose up -d mail

Accessing the Management Console

Once the container is running, you can access the MailDev Management Console by opening your browser and navigating to http://localhost:1080.

This console provides an interface to view and manage emails sent to the MailDev server.

Management Console

Testing Email Functionality

Sending an Email

If you’re using Windows, you can send test emails using the PowerShell Send-MailMessage command. Here’s an example:

Send-MailMessage `
  -from 'dev@localhost' `
  -to 'dev.to@localhost' `
  -subject 'Test Subject' `
  -body 'This is a test email.' `
  -smtpServer 'localhost' `
  -port 1025

Receiving an Email

After sending an email, navigate to the MailDev Management Console to verify that the email has been received.

Received Email

Conclusion

MailDev simplifies the process of testing email functionality during application development. By using Docker, you can easily set up a local mail server with minimal configuration.

Happy Coding! 🚀

Takahiro Iwasa

Takahiro Iwasa

Software Developer at KAKEHASHI Inc.
Involved in the requirements definition, design, and development of cloud-native applications using AWS. Now, building a new prescription data collection platform at KAKEHASHI Inc. Japan AWS Top Engineers 2020-2023.