How crazy-max/docker-msmtpd works
1. What this repo is
- This repository builds and ships a container image for msmtpd, a lightweight SMTP relay.
- It is not an application with a server/UI; the core product is the runtime Docker image published to Docker Hub and GHCR.
2. Primary runtime boundary
- The container exposes a single SMTP relay port: 2500.
- Incoming mail is accepted by msmtpd inside the container and then forwarded to an upstream SMTP server configured by environment variables.
3. Core data flow
- External clients connect to port 2500 on the container.
- msmtpd reads runtime configuration derived from environment variables such as SMTP_HOST, SMTP_PORT, SMTP_TLS, SMTP_AUTH, and related message/header options.
- The relay then authenticates and forwards mail to the configured upstream SMTP host.
4. Configuration model
- The container is configured almost entirely through environment variables rather than files baked into the image.
- Sensitive values can also be provided via *_FILE variants for Docker secrets, specifically for SMTP_USER and SMTP_PASSWORD.
- Runtime options cover transport security, auth, EHLO domain, envelope-from behavior, header rewriting, and DSN behavior.
5. Container bootstrap / init layer
- The rootfs/etc/cont-init.d/ directory contains container startup scripts that prepare the runtime environment before the service starts.
- Based on the filenames, these scripts handle:
- log directory fixes,
- UID/GID adjustment for non-root execution,
- config generation or normalization,
- service definition creation.
- This suggests the image uses an init system pattern where bootstrapping is separated from the long-running SMTP process.
6. Non-root execution and identity management
- A key architectural constraint is that the daemon runs as a non-root user.
- PUID and PGID are used to align the container process with host/user expectations, which affects file ownership and permissions inside mounted volumes or logs.
7. Build and packaging
- The image is built from source with Docker Buildx and docker-bake.hcl.
- The repo is set up for multi-platform builds, covering multiple Linux architectures.
- The Dockerfile and root filesystem layout indicate a packaging model where a base image is assembled with the compiled/bundled msmtpd runtime and init scripts.
8. Distribution targets
- The image is published to:
- Docker Hub as crazymax/msmtpd
- GitHub Container Registry as ghcr.io/crazy-max/msmtpd
- The README and workflows show this repo is meant to produce a reproducible container artifact rather than a library or service component.
9. Deployment examples
- examples/compose/compose.yml demonstrates the expected Docker Compose deployment pattern.
- examples/kubernetes/deployment.yaml shows how the same container is deployed in Kubernetes.
- These examples are important because they document the minimal runtime wiring: image, port exposure, and environment-based SMTP configuration.
10. Testing and validation
- The test/compose.yml file suggests validation is done through containerized integration testing, likely exercising startup and config behavior in a Compose environment.
- GitHub Actions workflows (build.yml, test.yml, labels.yml, zizmor.yml) handle build, test, and repository hygiene checks.
11. Operational dependencies
- The only external service the runtime fundamentally depends on is the upstream SMTP relay server specified by SMTP_HOST.
- Optional external integrations are the container registries used for distribution and the notification/build automation in GitHub Actions.
12. Diagram boundaries to capture
- A useful architecture diagram should show:
- Client SMTP producers → container port 2500
- Container init scripts → configure user, logs, and service startup
- msmtpd relay process → applies env-based policy and forwards mail
- Upstream SMTP server → receives relayed messages
- Separate lanes for build/publish pipeline and example deployment manifests.
Main entry points: Dockerfile Dockerfile · build.yml Build workflow · compose.yml Compose example · 00-fix-logs.sh Fix logs
Components 19
Runtime image
Containerized msmtpd relay and its startup configuration
- SMTP clients · Mail senders connecting to the relay
- Port 2500 · Container SMTP relay entrypoint
- Env config · SMTP_HOST, SMTP_PORT, TLS, auth, headers, DSN, and related behavior
- Secret files · *_FILE variants for SMTP user and password
- msmtpd · Accepts mail and forwards it to an upstream SMTP server
- Upstream SMTP · Destination relay server configured by SMTP_HOST
Bootstrap
Init scripts and service wiring inside the image
- Fix logs · Prepares log directory ownership and access
rootfs/etc/cont-init.d/00-fix-logs.sh - Fix uid/gid · Aligns container identity with PUID and PGID
rootfs/etc/cont-init.d/01-fix-uidgid.sh - Config init · Generates or normalizes runtime configuration
rootfs/etc/cont-init.d/02-config.sh - Service init · Creates the service definition for startup
rootfs/etc/cont-init.d/03-create-service.sh
Build and publish
Image build, multi-platform packaging, and registry distribution
- Dockerfile · Assembles the runtime image and bundled msmtpd components
Dockerfile - Buildx bake · Multi-platform build orchestration
docker-bake.hcl - Build workflow · Build and publish automation in GitHub Actions
.github/workflows/build.yml - Test workflow · Validation workflow for the container image and config behavior
.github/workflows/test.yml - Docker Hub · Published image destination cra ymax/msmtpd
- GHCR · Published image destination ghcr.io/crazy-max/msmtpd
Examples and tests
Deployment manifests and container-based validation
- Compose example · Docker Compose wiring for the relay container
examples/compose/compose.yml - K8s example · Kubernetes deployment manifest for the image
examples/kubernetes/deployment.yaml - Test compose · Compose-based runtime validation setup
test/compose.yml
Connections 23
- SMTP clients → Port 2500: connect to · External senders reach the exposed SMTP port
- Port 2500 → msmtpd: accepts · The container port feeds the relay process
- Env config → msmtpd: configures · Runtime behavior is driven by environment variables
- Secret files → msmtpd: secrets for · Credentials may be provided through file-backed secrets
- msmtpd → Upstream SMTP: forwards to · Accepted mail is relayed to the configured upstream server
- Fix logs → msmtpd: prepares · Ensures log paths are usable before the service starts
- Fix uid/gid → msmtpd: sets identity · Adjusts permissions for non-root execution
- Config init → Env config: materializes · Normalizes environment-derived settings into runtime config
- Service init → msmtpd: starts · Defines the long-running relay service
- Dockerfile → msmtpd: packages · Build recipe assembles the runtime image around the relay
- Dockerfile → Fix logs: includes · Image embeds init scripts in the root filesystem
- Dockerfile → Fix uid/gid: includes · Image embeds init scripts in the root filesystem
- Dockerfile → Config init: includes · Image embeds init scripts in the root filesystem
- Dockerfile → Service init: includes · Image embeds init scripts in the root filesystem
- Buildx bake → Dockerfile: builds · Buildx bake orchestrates image builds
- Build workflow → Buildx bake: drives · CI uses the build plan for multi-platform publishing
- Build workflow → Docker Hub: publishes · Build output is pushed to Docker Hub
- Build workflow → GHCR: publishes · Build output is pushed to GitHub Container Registry
- Compose example → msmtpd: runs · Demonstrates the expected container runtime wiring
- Compose example → Env config: sets · Shows the required environment-based SMTP configuration
- K8s example → msmtpd: deploys · Shows Kubernetes deployment of the same image
- Test compose → msmtpd: validates · Containerized integration testing exercises startup and config behavior
- Test workflow → Test compose: runs · CI executes the Compose-based validation fixture