Testing of email notifications with GreenMail, a mock mail server
Motivation
TestPyramid
Unit
Integration
e2e
Manual
€€€
€
TestPyramid for email notifications
avoid where possible
styled HTML Mails
smoke tests
happy paths
mail server communication
sending & receiving mails
triggers
mail content
Unit
Integration
e2e
Manual
Status quo - manual testing
no email server
error
write emails into log
production email server
change all email addresses
list of allowed recipients
testing not possible
digging in the logs
testing HTML mails not possible
danger of leaks
connection needed
resource allocation
many notifications in large teams
environment agnostic code
Status quo - automatic testing
no e2e tests
no integration tests
Unit test
triggers & conditions
mail content
GreenMail
intial release: ~2006
latest release: April 2021
enables email integration testing
sending mails
receiving mails
prevents accidental email leaking to real email servers
embeddable as dependency or runnable as email server
Demo
GreenMail in the TestPyramid
Unit
Integration
e2e
Manual
Advantages using GreenMail
no digging in the logs
testing Text and HTML mails easily
no fear of leaks
same code in all environments
all local
no network connection needed
receive your own mails only
local (hardware) resources
Further reading & sources
This slides
https://slides.com/jensknipper/greenmail
Demo code
https://github.com/JensKnipper/greenmail-example
GreenMail
https://greenmail-mail-test.github.io/greenmail/
Casper email sequence
https://www.indiehackers.com/post/what-a-great-email-sequence-looks-like-34e7d9a43c
TestPyramid
https://martinfowler.com/bliki/TestPyramid.html