Setting Up MailDev: A Local Mail Server with Docker
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.
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.
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! 🚀