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 customized using 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, 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

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 an email, navigate to the MailDev Management Console to verify that the email has been received.

Received Email

Conclusion

Building a small Docker container running MailDev and sending a test email to it confirmed that outgoing mail could be captured and inspected without a real inbox involved. Because MailDev exposes both an SMTP listener on 1025 and a web console on 1080 from a single container, pointing an application’s mail configuration at localhost:1025 is enough to capture every outgoing message and inspect it visually. That makes it a convenient way to verify email-triggering code paths — password resets, notifications, and the like — during local development, though the container is only intended to catch mail rather than deliver it, so it should stay confined to 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.