MailDev - Mail Server on Your Local Environment

MailDev - Mail Server on Your Local Environment

Takahiro Iwasa
(岩佐 孝浩)
Takahiro Iwasa (岩佐 孝浩)
1 min read
MailDev

When developing an application, MailDev is useful to send and receive emails within user’s local environment.

Launching MailDev

Create 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 its management console and 1025 for SMTP. These can be changed by options.

Create docker-compose.yml using the example below.

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

Launch the Docker container with the following command.

docker-compose up -d mail

Management Console

To access the management console, open your browser and go to http://localhost:1080.

Testing

Sending Mail

Because I’m writing this post using Windows, the example below uses Send-MailMessage command by PowerShell.

Send-MailMessage `
>> -from 'dev@localhost' `
>> -to 'dev.to@localhost' `
>> -subject 'subject' `
>> -body 'test' `
>> -smtpServer 'localhost' `
>> -port 1025

Receiving Mail

You should see a new email received in the management console.

Takahiro Iwasa
(岩佐 孝浩)

Takahiro Iwasa (岩佐 孝浩)

Software Developer at iret, Inc.
Architecting and developing cloud native applications mainly with AWS. Japan AWS Top Engineers 2020-2023