Email Testing in Development
Email Testing in Development
Section titled “Email Testing in Development”This document explains how to test emails in your local development environment using either GreenMail or MailDev.
Available Email Testing Tools
Section titled “Available Email Testing Tools”The Hatchgrid project supports two email testing tools:
- GreenMail (default) - A test suite for email servers that provides a web interface to view sent emails.
- MailDev - A simple way to test emails with an easy-to-use web interface.
Using GreenMail (Default)
Section titled “Using GreenMail (Default)”GreenMail is configured by default in the project. When you run the application with Docker Compose, GreenMail will be started automatically.
- SMTP Server: localhost:3025
- Web Interface: http://localhost:8081
- Default User: developer:secret@hatchgrid.local
Using MailDev
Section titled “Using MailDev”To switch to MailDev for email testing:
# Run the switch script./scripts/switch-mail-server.sh maildev
This will:
- Stop any running email servers
- Start MailDev with the correct configuration
- Display configuration information
- SMTP Server: localhost:1025
- Web Interface: http://localhost:1080
MailDev provides a clean, modern web interface for viewing emails and includes features like:
- HTML/Text email viewing
- Responsive design testing
- Email forwarding to real addresses
- API access for automated testing
Switching Back to GreenMail
Section titled “Switching Back to GreenMail”To switch back to GreenMail:
# Run the switch script./scripts/switch-mail-server.sh greenmail
Manual Configuration
Section titled “Manual Configuration”If you prefer to manually configure the email testing tool:
For MailDev
Section titled “For MailDev”- Edit
compose.yaml
to comment out GreenMail and uncomment MailDev - Update
application.yml
to use port 1025 for SMTP - Restart your Docker containers
For GreenMail
Section titled “For GreenMail”- Edit
compose.yaml
to comment out MailDev and uncomment GreenMail - Update
application.yml
to use port 3025 for SMTP - Restart your Docker containers
Testing Email Functionality
Section titled “Testing Email Functionality”To test email functionality:
- Start your application and the Docker services
- Register a new user or trigger any action that sends an email
- Open the web interface of your chosen email testing tool
- View the sent emails in the interface
Configuration in Spring Boot
Section titled “Configuration in Spring Boot”The email configuration is defined in application.yml
:
spring: mail: host: ${SMTP_HOST:localhost} port: ${SMTP_PORT:3025} # Change to 1025 for MailDev username: ${SMTP_USERNAME:developer} password: ${SMTP_PASSWORD:secret} properties: mail: smtp: auth: false starttls: enable: false ssl: enable: false
Troubleshooting
Section titled “Troubleshooting”If you encounter issues with email testing:
- Ensure the SMTP port matches your email testing tool (3025 for GreenMail, 1025 for MailDev)
- Check that the Docker containers are running (
docker compose ps
) - Verify network connectivity between your application and the email server
- Check the logs of the email server container for any errors