Recently, I added a new email notification feature to my N1netails project — a developer-focused alerting tool built with Spring Boot. One of the contributors suggested we look into using MailHog for local email testing, which turned out to be a great fit.
📬 Now, new users receive a welcome email when signing up, and existing users get alerts via email when something important happens.
When deploying to production via N1netails Dashboard, I registered a real email address via Outlook. But for local development and testing, I needed a way to simulate sending emails without actually sending them.
That’s where MailHog came in — a lightweight, fake SMTP server with a built-in web UI for viewing test emails.
🔧 What is MailHog and Why Use It in a Spring Boot Project?
MailHog is a tool that captures outgoing emails sent from your app, so you can:
- ✅ Test email templates without spamming real inboxes
- ✅ Debug SMTP configurations locally
- ✅ Preview emails in a browser
It’s ideal for Spring Boot developers building user signup flows, alerting systems, or any feature involving transactional emails.
🚀 Step-by-Step: How to Use MailHog with Spring Boot
1. Install MailHog
Option A: Binary Download
Download the binary from MailHog GitHub Releases
# Example for Windows: mv MailHog_windows_amd64.exe mailhog.exe
Option B: Go
go install github.com/mailhog/MailHog@latest
Option C: Docker (Recommended)
docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog
2. Run MailHog
If you're using Docker, it's already running:
- SMTP Server →
localhost:1025
- Web UI → http://localhost:8025
3. Configure Spring Boot to Use MailHog
Update your application.yml
(or use Spring profiles):
View how it is configured in n1netails here application-email.yml
spring: mail: host: localhost port: 1025 username: dummy password: dummy from: support@n1netails.com properties: mail.smtp.auth: false mail.smtp.starttls.enable: false
Optional: Make it toggleable using environment variables:
n1netails: email: enabled: ${EMAIL_ENABLED:false}
4. Trigger an Email
You can test by creating an account on the live N1netails Dashboard — or just simulate it in your code.
5. Preview Emails in the Web UI
Go to http://localhost:8025 to:
- View email subject and content
- Inspect headers
- Test HTML rendering
🛠️ How N1netails Uses Email Templates (Spring Boot + Liquibase)
Here’s how I wired the backend email flow inside N1netails:
- Email templates are stored in the DB
- I load them via a Spring Data repository
- Dynamic content is injected using
{{placeholders}}
- Emails are sent using
JavaMailSender
Templates are pre-loaded using Liquibase.
📥 SQL Table for Templates
CREATE TABLE IF NOT EXISTS ntail.email_notification_template ( id BIGINT NOT NULL, name character varying(100), subject TEXT, html_body TEXT, CONSTRAINT email_notification_template_pkey PRIMARY KEY (id) );
🎨 HTML Welcome & Alert Email Templates
- Welcome & Alert Template SQL
- Includes
{{username}}
,{{n1netailsEmail}}
, and more
🧬 Spring Boot Code for Sending Emails in N1netails
Entity:
EmailNotificationTemplateEntity.java
Repository:
EmailNotificationTemplateRepository.java
Service:
EmailServiceImpl.java
It fetches the email template by name, applies dynamic parameters, and sends using JavaMailSender
.
✅ Summary
With MailHog, I was able to:
- Add robust email notifications to N1netails
- Test locally with no risk of spamming users
- Preview and iterate on email designs
- Keep emails stored and maintainable in a database
If you're building a Spring Boot SaaS, consider adding MailHog to your local dev workflow!
💬 If you found this useful or want to see more behind-the-scenes of N1netails, feel free to follow or ask questions. I'm building this open and dev-first. If you are interested in contributing you can view the GitHub
🦊 Happy coding!
Top comments (0)