This guide explains how to use the Docker setup and environment variables for the SMTP to JSON Server.
- Docker installed on your system
- Docker Compose (optional, for using docker-compose.yml)
-
Make sure all files are in the same directory:
smtp_json_server.py(your main application)requirements.txtDockerfile
-
Build the image:
docker build -t smtp-json-server:latest . -
Run the container with your webhook URL:
docker run -p 8025:8025 -e WEBHOOK_URL=https://your-webhook.com/emails smtp-json-server:latest
For easier management, you can use Docker Compose:
-
Update the
docker-compose.ymlfile with your actual webhook URL and API key:environment: - WEBHOOK_URL=https://your-actual-webhook.com/endpoint - API_KEY=your_actual_api_key
-
Start the service:
docker-compose up -d
This will start the SMTP server in detached mode, exposing port 8025.
The application supports the following environment variables:
| Variable | Description | Default |
|---|---|---|
SMTP_HOST |
Hostname for SMTP server to bind to | 0.0.0.0 |
SMTP_PORT |
Port for SMTP server to listen on | 8025 |
WEBHOOK_URL |
URL to POST email JSON data (required) | None |
API_KEY |
API key for webhook authentication (optional) | None |
LOG_LEVEL |
Logging level (DEBUG, INFO, WARNING, ERROR) | INFO |
You can create a .env file for local development:
SMTP_HOST=0.0.0.0
SMTP_PORT=8025
WEBHOOK_URL=https://webhook.site/your-unique-id
API_KEY=test_key_123
LOG_LEVEL=DEBUG
The included GitHub Actions workflow automates building and publishing your Docker image to GitHub Container Registry (ghcr.io).
-
Create the
.github/workflowsdirectory in your repository:mkdir -p .github/workflows
-
Place the
docker-build.ymlfile in this directory. -
Commit and push to your GitHub repository:
git add . git commit -m "Add Docker and CI configuration" git push
-
The workflow runs on:
- Pushes to main/master branches
- Creation of tags starting with "v" (e.g., v1.0.0)
- Pull requests to main/master branches
-
For pushes to the main branch, it builds and pushes the image with the "latest" tag
-
For tagged releases, it creates versioned tags (e.g., v1.0.0, v1.0, v1)
-
For pull requests, it builds but doesn't push the image
After the workflow successfully runs on your main branch or a tag, you can pull and run your image from GitHub Container Registry:
# Pull the image (replace 'username/repo' with your GitHub username and repository name)
docker pull ghcr.io/username/repo:latest
# Run the image
docker run -p 8025:8025 -v $(pwd)/emails:/app/emails ghcr.io/username/repo:latestThe workflow uses the automatic GITHUB_TOKEN provided by GitHub Actions for authentication. This token has permissions to push packages to the GitHub Container Registry for your repository.
If you want to publish to Docker Hub instead, you'll need to modify the workflow to use Docker Hub credentials stored as GitHub repository secrets.