Skip to content

Email Testing with MailDev

Hatchgrid supports MailDev as an alternative email testing server for development and testing environments. MailDev is a simple SMTP server with a web interface that makes it easy to test and view emails during development.

MailDev is configured as a Docker service in the project’s infrastructure:

infra/maildev/maildev-compose.yml
services:
maildev:
image: djfarrelly/maildev:latest
container_name: maildev
ports:
- "1025:25" # SMTP
- "1080:80" # Web interface
networks:
- backend
- frontend
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "25"]
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
labels:
org.springframework.boot.ignore: true
networks:
frontend:
external: true
backend:
external: true

MailDev provides the following services:

ProtocolPortDescription
SMTP1025Simple Mail Transfer Protocol (sending emails)
Web UI1080Web interface for email management

You can start MailDev using Docker Compose:

Terminal window
docker compose -f infra/maildev/maildev-compose.yml up -d

Access the MailDev web interface at: http://localhost:1080

The web interface allows you to:

  • View all received emails
  • Inspect email headers and content
  • Test responsive design with different screen sizes
  • Forward emails to real email addresses

Configure your Spring Boot application to use MailDev for email testing:

application-dev.yml
spring:
mail:
host: localhost
port: 1025
protocol: smtp
properties:
mail:
smtp:
auth: false
starttls:
enable: false

Hatchgrid supports both GreenMail and MailDev for email testing. You can switch between them using the provided script:

Terminal window
./scripts/switch-mail-server.sh [greenmail|maildev]
  1. Use MailDev for all email testing - Never use real email services in development
  2. Check the web interface regularly - Monitor emails during development
  3. Test responsive design - MailDev allows testing emails in different screen sizes
  1. Never use MailDev in production - It’s designed for testing only
  2. Disable authentication in test environments - Simplifies testing setup

If ports 1025 or 1080 are already in use:

Terminal window
# Check what's using port 1025
lsof -i :1025
# Check what's using port 1080
lsof -i :1080
# Stop conflicting services or change MailDev port mapping

Ensure MailDev is running and healthy:

Terminal window
# Check container status
docker compose -f infra/maildev/maildev-compose.yml ps
# Check container logs
docker compose -f infra/maildev/maildev-compose.yml logs
# Test SMTP connection
echo quit | telnet localhost 1025