Running MailDev as a Local Mail Server with Docker

Running MailDev as a Local Mail Server with Docker

Running MailDev in Docker to capture and inspect outgoing mail locally, without a real inbox involved.

Takahiro Iwasa
2 min read

Setting Up MailDev with Docker

Create a Dockerfile using the example below.

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

MailDev uses the following ports:

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

These ports can be changed with MailDev command-line options.

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

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

Bring up the container:

Terminal window
docker-compose up -d mail

Once the container is running, open http://localhost:1080 in a browser to access the MailDev management console.

The console displays and manages messages sent to the MailDev server.

Management Console

Testing Email Functionality

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

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

After sending the email, open the MailDev management console and verify that the message was received.

Received Email

Conclusion

A Docker container running MailDev can capture and display outgoing email without using a real inbox.

MailDev exposes an SMTP listener on port 1025 and a web console on port 1080. Configure the application to use localhost:1025 as its SMTP server, then inspect captured messages in the browser.

This setup is useful for testing password resets, notifications, and other email-related behavior locally. MailDev captures messages instead of delivering them, so use it only in development and test environments.

About the author

Takahiro Iwasa

Takahiro Iwasa

Software Developer

This blog shares technical notes from hands-on projects—architecture, implementation, and AWS service integrations.