I'll show you how to run a MailHog local SMTP server in a Docker container with the JIM extension which will trigger errors when sending emails from a simple Python script.
- Docker Desktop
- Miniconda (optional)
If you want to use a virtual environment, you can create one with the following commands:
# Download latest Miniconda https://docs.conda.io/en/latest/miniconda.html for your OS
# Create a virtual environment
conda create -n mailhog-jim-python python=3.10
conda activate mailhog-jim-python
# Clone the repository
git clone https://github.com/garis-space/mailhog-jim-python.git
cd mailhog-jim-python
# Environment variables (edit as needed)
cp .env.example .env
MailHog use Jim chaos monkey extension to fail sending emails. You can configure the probability of failure in the .env
file. Default value is 0.2 and it means that 20% of emails will be rejected.
# Start Docker Compose
docker compose up
# Run the Python script
python main.py
Open your browser and go to http://localhost:8025 to see the email sent by the Python script.
docker compose down
conda deactivate
conda remove -n mailhog-jim-python --all