About
When developing an email solution, you want:
- to prevent that emails are going into the wild
- to catch this email in order to assert that they were send with the good content.
There is several strategy that you can use.
- implement a filter plugin inside your Email library that will catch the email (mock).
- run locally a SMTP server dedicated for development purpose that will receive your test email
- inject / replace your production code by a test code via dependency injection.
Library
Local SMTP server
Simple SMTP server that accepts all messages and stores them. Your unit test code can then examine the messages (or lack thereof) and verify their validity.
- C: https://github.com/ChangemakerStudios/Papercut-SMTP - 2-in-1 quick email viewer AND built-in SMTP server (designed to receive messages only)
- Node: https://github.com/maildev/maildev - SMTP Server + Web Interface for viewing and testing emails during development.
- Java:
- Wiser - Wiser is a simple SMTP server accepts all messages and stores them in an internal ArrayList.
- https://github.com/kirviq/dumbster - Simple SMTP server that collects the email
- https://github.com/gessnerfl/fake-smtp-server (SMTP Service with Rest API) - Web Interface available at http://localhost:5080
docker run --name smtp -p 5025:5025 -p 5080:5080 -p 5081:5081 -d gessnerfl/fake-smtp-server
Filter
- Java Mail Pluggable Plugin that catch the email send mock-javamail