### Kubernetes Deployment Example Source: https://github.com/crazy-max/docker-msmtpd/blob/master/README.md Example Kubernetes deployment configuration for the msmtpd container. This snippet defines a Deployment resource, including the container image, port exposure, and environment variables for SMTP relay configuration. It requires a `deployment.yaml` file. ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: msmtpd labels: app: msmtpd spec: replicas: 1 selector: matchLabels: app: msmtpd template: metadata: labels: app: msmtpd spec: containers: - name: msmtpd image: crazymax/msmtpd:latest ports: - containerPort: 2500 env: - name: TZ value: "Etc/UTC" - name: PUID value: "1000" - name: PGID value: "1000" - name: SMTP_HOST value: "smtp.example.com" - name: SMTP_PORT value: "587" - name: SMTP_TLS value: "on" - name: SMTP_AUTH value: "on" - name: SMTP_USER value: "user@example.com" - name: SMTP_PASSWORD valueFrom: secretKeyRef: name: msmtpd-secrets key: smtp_password - name: SMTP_DOMAIN value: "example.com" - name: SMTP_FROM value: "sender@example.com" ``` -------------------------------- ### Run msmtpd Container Command Line Source: https://github.com/crazy-max/docker-msmtpd/blob/master/README.md Minimal command to run the msmtpd container directly using `docker run`. This example highlights the essential parameters for starting the container, including port mapping and setting the required `SMTP_HOST` environment variable. It's a quick way to test or run the service without Docker Compose or Kubernetes. ```bash docker run -d -p 2500:2500 --name msmtpd \ -e "SMTP_HOST=smtp.example.com" \ crazymax/msmtpd ``` -------------------------------- ### Kubernetes Deployment and Verification Commands Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt These bash commands are used to deploy the msmtpd Kubernetes configuration, verify the deployment status of all resources within the 'msmtpd' namespace, and inspect the logs of the msmtpd StatefulSet. It also includes an example of how to test connectivity to the SMTP service from within the cluster. ```bash # Deploy to Kubernetes kubectl apply -f deployment.yaml # Verify deployment kubectl get all -n msmtpd kubectl logs -n msmtpd statefulset/msmtpd # Test from within cluster kubectl run -n msmtpd -it --rm debug --image=alpine --restart=Never -- sh # Inside pod: apk add netcat-openbsd echo -e "EHLO test\nQUIT" | nc smtp 25 # Expected output: # namespace/msmtpd created # configmap/msmtpd-config created # statefulset.apps/msmtpd created # service/smtp created ``` -------------------------------- ### Docker Compose Deployment Example Source: https://github.com/crazy-max/docker-msmtpd/blob/master/README.md Example Docker Compose configuration for deploying the msmtpd container. This snippet demonstrates how to set up the service, map ports, and define environment variables for SMTP relay configuration. It requires a `docker-compose.yml` file. ```yaml version: "3.8" services: msmtpd: image: crazymax/msmtpd:latest container_name: msmtpd ports: - "2500:2500" environment: - TZ=Etc/UTC - PUID=1000 - PGID=1000 - SMTP_HOST=smtp.example.com - SMTP_PORT=587 - SMTP_TLS=on - SMTP_AUTH=on - SMTP_USER=user@example.com - SMTP_PASSWORD=password - SMTP_DOMAIN=example.com - SMTP_FROM=sender@example.com restart: unless-stopped ``` -------------------------------- ### Custom UID/GID Configuration for msmtpd Container Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt Example of running the msmtpd container with custom PUID and PGID environment variables to ensure host filesystem compatibility. ```bash # Run with custom PUID/PGID docker run -d -p 2500:2500 --name msmtpd \ -e "PUID=1001" \ -e "PGID=1001" \ -e "SMTP_HOST=smtp.example.com" \ crazymax/msmtpd # Verify user configuration docker exec msmtpd id msmtpd # Expected: uid=1001(msmtpd) gid=1001(msmtpd) # Check process ownership docker exec msmtpd ps aux | grep msmtpd # Expected: msmtpd process running as UID 1001 ``` -------------------------------- ### Basic Docker Run for SMTP Relay Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt This snippet shows how to run the docker-msmtpd container with a comprehensive set of environment variables for basic SMTP relay configuration. It specifies the host, port, authentication, TLS settings, and header manipulation. The container is published on port 2500 and expected to start successfully, with logs indicating configuration and daemon startup. A health check using EHLO is also described. ```bash docker run -d \ --name msmtpd \ -p 2500:2500 \ -e "TZ=UTC" \ -e "PUID=1500" \ -e "PGID=1500" \ -e "SMTP_HOST=smtp.gmail.com" \ -e "SMTP_PORT=587" \ -e "SMTP_TLS=on" \ -e "SMTP_STARTTLS=on" \ -e "SMTP_TLS_CHECKCERT=on" \ -e "SMTP_AUTH=on" \ -e "SMTP_USER=user@gmail.com" \ -e "SMTP_PASSWORD=app_password" \ -e "SMTP_DOMAIN=localhost" \ -e "SMTP_FROM=%F@example.com" \ -e "SMTP_ALLOW_FROM_OVERRIDE=on" \ -e "SMTP_SET_FROM_HEADER=auto" \ -e "SMTP_SET_DATE_HEADER=auto" \ -e "SMTP_REMOVE_BCC_HEADERS=on" \ -e "SMTP_UNDISCLOSED_RECIPIENTS=off" \ -e "SMTP_DSN_NOTIFY=failure,delay" \ -e "SMTP_DSN_RETURN=headers" \ crazymax/msmtpd # Expected output: Container starts and listens on port 2500 # Logs show: "Creating configuration..." and msmtpd daemon startup # Health check: EHLO command returns 250 status ``` -------------------------------- ### Docker Secrets Creation and Deployment Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt This bash snippet demonstrates how to create external Docker secrets for SMTP credentials and then deploy a Docker Compose stack. It uses `docker secret create` to store the username and password, followed by `docker compose up -d` to start the services. Commands to verify the deployment and test the SMTP connection using `nc` are also included. ```bash # Create external secrets echo "user@gmail.com" | docker secret create smtp_user - echo "your_app_password" | docker secret create smtp_password - # Deploy the stack docker compose up -d # Verify deployment docker compose ps docker compose logs -f # Test SMTP connection echo -e "EHLO localhost\nQUIT" | nc localhost 2500 # Expected output: # 220 localhost ESMTP # 250-localhost # 250 PIPELINING # 221 2.0.0 Bye ``` -------------------------------- ### Multi-Platform Docker Image Build with Buildx Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt This section provides bash commands for cloning the msmtpd repository and building Docker images using Docker Buildx. It covers building for the local platform and for multiple architectures, as well as inspecting the available platforms for a multi-platform image. ```bash # Clone repository git clone https://github.com/crazy-max/docker-msmtpd.git cd docker-msmtpd # Build for local platform (amd64, arm64, etc.) docker buildx bake # Expected output: # [+] Building 45.2s (23/23) FINISHED # => => naming to docker.io/library/msmtpd:local # Build multi-platform image docker buildx bake image-all # View available platforms docker buildx imagetools inspect crazymax/msmtpd --format "{{json .Manifest}}" | \ jq -r '.manifests[] | select(.platform.os != null) | .platform | "\(.os)/\(.architecture)\(if .variant then "/" + .variant else "" end)"' # Expected platforms: # linux/386 # linux/amd64 # linux/arm/v6 # linux/arm/v7 # linux/arm64 # linux/ppc64le # linux/s390x # Test local build docker run -d -p 2500:2500 --name msmtpd \ -e "SMTP_HOST=smtp.example.com" \ msmtpd:local # Verify health docker ps --filter name=msmtpd --format "{{.Names}}: {{.Status}}" ``` -------------------------------- ### Build Docker Images with Docker Buildx Bake Source: https://github.com/crazy-max/docker-msmtpd/blob/master/README.md Commands to build the Docker image locally using Docker Buildx Bake. It supports building the default image and multi-platform images. Dependencies include git and Docker with Buildx. ```shell git clone https://github.com/crazy-max/docker-msmtpd.git cd docker-msmtpd # Build image and output to docker (default) docker buildx bake # Build multi-platform image docker buildx bake image-all ``` -------------------------------- ### Kubernetes StatefulSet Deployment for msmtpd Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt This YAML defines a complete Kubernetes deployment for msmtpd, including a namespace, ConfigMap for credentials, a StatefulSet for the msmtpd application, and a Service for network access. It configures environment variables for SMTP settings and mounts credentials from the ConfigMap. ```yaml --- apiVersion: v1 kind: Namespace metadata: name: msmtpd --- apiVersion: v1 kind: ConfigMap metadata: name: msmtpd-config namespace: msmtpd data: smtp_user: | user@gmail.com smtp_password: | your_app_password --- apiVersion: apps/v1 kind: StatefulSet metadata: name: msmtpd namespace: msmtpd labels: app: msmtpd spec: serviceName: msmtpd replicas: 1 selector: matchLabels: app: msmtpd template: metadata: labels: app: msmtpd name: msmtpd spec: containers: - name: msmtpd image: crazymax/msmtpd imagePullPolicy: IfNotPresent env: - name: TZ value: Europe/Paris - name: PUID value: "1500" - name: PGID value: "1500" - name: SMTP_HOST value: "smtp.gmail.com" - name: SMTP_PORT value: "587" - name: SMTP_TLS value: "on" - name: SMTP_STARTTLS value: "on" - name: SMTP_TLS_CHECKCERT value: "on" - name: SMTP_AUTH value: "on" - name: SMTP_USER_FILE value: "/run/secrets/smtp_user" - name: SMTP_PASSWORD_FILE value: "/run/secrets/smtp_password" - name: SMTP_DOMAIN value: "localhost" volumeMounts: - name: msmtpd-config-user mountPath: /run/secrets/smtp_user subPath: smtp_user - name: msmtpd-config-password mountPath: /run/secrets/smtp_password subPath: smtp_password volumes: - name: msmtpd-config-user configMap: name: msmtpd-config - name: msmtpd-config-password configMap: name: msmtpd-config --- apiVersion: v1 kind: Service metadata: name: smtp namespace: msmtpd spec: selector: app: msmtpd ports: - port: 25 targetPort: 2500 protocol: TCP name: smtp ``` -------------------------------- ### Advanced msmtpd Docker Run with Header and DSN Config Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt An advanced Docker run command for msmtpd, showcasing configuration of header manipulation (From, Date, BCC) and Delivery Status Notification (DSN) settings. ```bash # Advanced configuration with header manipulation docker run -d -p 2500:2500 --name msmtpd \ -e "SMTP_HOST=smtp.example.com" \ -e "SMTP_PORT=587" \ -e "SMTP_TLS=on" \ -e "SMTP_AUTH=on" \ -e "SMTP_USER=user@example.com" \ -e "SMTP_PASSWORD=password" \ -e "SMTP_FROM=%F@example.com" \ -e "SMTP_ALLOW_FROM_OVERRIDE=on" \ -e "SMTP_SET_FROM_HEADER=auto" \ -e "SMTP_SET_DATE_HEADER=auto" \ -e "SMTP_REMOVE_BCC_HEADERS=on" \ -e "SMTP_UNDISCLOSED_RECIPIENTS=on" \ -e "SMTP_DSN_NOTIFY=failure,delay,success" \ -e "SMTP_DSN_RETURN=full" \ crazymax/msmtpd # Generated /etc/msmtprc content: # account default # logfile - # syslog off # host smtp.example.com # port 587 # tls on # tls_starttls on # auth on # user user@example.com # password password # from %F@example.com # allow_from_override on # set_from_header auto # set_date_header auto # remove_bcc_headers on # undisclosed_recipients on # dsn_notify failure,delay,success # dsn_return full ``` -------------------------------- ### Inspect Docker Image Platforms with Docker Buildx and jq Source: https://github.com/crazy-max/docker-msmtpd/blob/master/README.md Shell command to inspect the platforms supported by a Docker image using `docker buildx imagetools inspect` and `jq`. This helps determine OS and architecture compatibility. Dependencies include Docker Buildx and jq. ```shell docker buildx imagetools inspect crazymax/msmtpd --format "{{json .Manifest}}" | \ jq -r ".manifests[] | select(.platform.os != null and .platform.os != \"unknown\") | .platform | \"\(.os)/\(.architecture)\(if .variant then \"/\" + .variant else \"\" end)" ``` -------------------------------- ### Docker Compose for PHP App and msmtpd Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt A Docker Compose configuration defining services for msmtpd and a PHP application, demonstrating how they can interact within a Docker network. ```yaml # Docker Compose with PHP application services: msmtpd: image: crazymax/msmtpd environment: - SMTP_HOST=smtp.gmail.com - SMTP_PORT=587 - SMTP_TLS=on - SMTP_STARTTLS=on - SMTP_AUTH=on - SMTP_USER=user@gmail.com - SMTP_PASSWORD=app_password networks: - app_network php_app: image: php:8.2-fpm volumes: - ./app:/var/www/html depends_on: - msmtpd networks: - app_network networks: app_network: driver: bridge ``` -------------------------------- ### Container Management Commands for msmtpd Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt Essential Docker commands for managing the msmtpd container, including health checks, log viewing, configuration inspection, testing, monitoring, restarting, and updating. ```bash # Check container health status docker inspect msmtpd --format='{{.State.Health.Status}}' # Output: healthy # View health check logs docker inspect msmtpd --format='{{range .State.Health.Log}}{{.Output}}{{end}}' # Manual health check docker exec msmtpd sh -c 'echo EHLO localhost | nc 127.0.0.1 2500 | grep 250' # Expected: 250-localhost # View container logs docker logs -f msmtpd # View msmtpd configuration docker exec msmtpd cat /etc/msmtprc # Test configuration docker exec msmtpd msmtp --serverinfo # Send test email from within container docker exec -it msmtpd sh -c 'echo -e "Subject: Test\n\nTest body" | msmtp -f sender@example.com recipient@example.com' # Monitor resource usage docker stats msmtpd --no-stream # Restart container docker restart msmtpd # Update to latest version docker pull crazymax/msmtpd:latest docker stop msmtpd docker rm msmtpd # Re-run docker run command with new image ``` -------------------------------- ### Send Email using Python smtplib with msmtpd Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt Demonstrates how to send a test email using Python's smtplib library, connecting to an msmtpd instance running on localhost. ```python import smtplib from email.mime.text import MIMEText msg = MIMEText("Test email body") msg['Subject'] = 'Test Email via msmtpd' msg['From'] = 'sender@example.com' msg['To'] = 'recipient@example.com' with smtplib.SMTP('localhost', 2500) as smtp: smtp.send_message(msg) print("Email sent successfully") ``` -------------------------------- ### Configure PHP mail() and PHPMailer with msmtpd Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt Shows how to configure PHP applications to send emails via msmtpd. This includes setting up the default mail() function and using the PHPMailer library. ```php isSMTP(); $mail->Host = 'msmtpd'; $mail->Port = 2500; $mail->SMTPAuth = false; $mail->setFrom('sender@example.com', 'Sender Name'); $mail->addAddress('recipient@example.com', 'Recipient Name'); $mail->Subject = 'Test Email from PHPMailer'; $mail->Body = 'This is a test email sent through msmtpd relay.'; if ($mail->send()) { echo "Email sent successfully\n"; } else { echo "Error: " . $mail->ErrorInfo . "\n"; } ?> ``` -------------------------------- ### Test msmtpd SMTP Functionality Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt Comprehensive bash script to test the SMTP relay functionality of a running msmtpd container. It covers basic handshake, mail commands, full transactions, and configuration validation. ```bash # Start test container docker run -d -p 2500:2500 --name msmtpd-test \ -e "SMTP_HOST=smtp.mailtrap.io" \ -e "SMTP_PORT=2525" \ -e "SMTP_AUTH=on" \ -e "SMTP_USER=test_user" \ -e "SMTP_PASSWORD=test_pass" \ crazymax/msmtpd # Wait for container to be healthy timeout 30 sh -c 'until docker inspect msmtpd-test --format="{{.State.Health.Status}}" | grep -q healthy; do sleep 1; done' # Test 1: Basic SMTP handshake echo -e "EHLO test\nQUIT" | nc localhost 2500 | grep -q "250" && echo "PASS: SMTP handshake" || echo "FAIL: SMTP handshake" # Test 2: MAIL FROM command (echo "EHLO test"; echo "MAIL FROM:"; echo "QUIT") | nc localhost 2500 | grep -q "250 2.1.0" && echo "PASS: MAIL FROM" || echo "FAIL: MAIL FROM" # Test 3: Full email transaction result=$(( echo "EHLO test" echo "MAIL FROM:" echo "RCPT TO:" echo "DATA" echo "Subject: Test" echo "" echo "Test body" echo "." echo "QUIT" ) | nc localhost 2500 | grep -c "250") [ "$result" -ge 3 ] && echo "PASS: Full transaction" || echo "FAIL: Full transaction" # Test 4: Configuration validation docker exec msmtpd-test test -f /etc/msmtprc && echo "PASS: Config exists" || echo "FAIL: Config missing" # Test 5: Process running docker exec msmtpd-test pgrep msmtpd > /dev/null && echo "PASS: Process running" || echo "FAIL: Process not running" # Cleanup docker stop msmtpd-test docker rm msmtpd-test # Expected output: # PASS: SMTP handshake # PASS: MAIL FROM # PASS: Full transaction # PASS: Config exists # PASS: Process running ``` -------------------------------- ### Testing SMTP Relay with Swaks Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt This command demonstrates how to test the msmtpd SMTP relay service using swaks (Swiss Army Knife for SMTP). It specifies the recipient, sender, server address and port, and includes custom headers and a message body for the test email. ```bash # Using swaks (Swiss Army Knife for SMTP) swaks --to recipient@example.com \ --from sender@example.com \ --server localhost:2500 \ --header "Subject: Test from swaks" \ --body "Test message body" ``` -------------------------------- ### Testing SMTP Relay with Netcat Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt This bash script demonstrates how to test the msmtpd SMTP relay service running on localhost:2500 using netcat (nc). It sends a series of SMTP commands, including EHLO, MAIL FROM, RCPT TO, DATA, and QUIT, and shows the expected server responses. ```bash # Using netcat (nc) ( echo "EHLO localhost" echo "MAIL FROM:" echo "RCPT TO:" echo "DATA" echo "From: sender@example.com" echo "To: recipient@example.com" echo "Subject: Test Email" echo "" echo "This is a test email sent through msmtpd relay." echo "." echo "QUIT" ) | nc localhost 2500 # Expected output: # 220 localhost ESMTP # 250-localhost # 250 PIPELINING # 250 2.1.0 sender ok # 250 2.1.5 recipient ok # 354 enter mail, end with "." on a line by itself # 250 2.0.0 message accepted # 221 2.0.0 Bye ``` -------------------------------- ### Verify msmtpd User ID Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt Executes the 'id' command within a running msmtpd container to verify the user and group IDs, ensuring correct process execution. ```bash docker exec msmtpd id msmtpd ``` -------------------------------- ### Docker Compose for SMTP Relay with Secrets Source: https://context7.com/crazy-max/docker-msmtpd/llms.txt This YAML snippet defines a Docker Compose configuration for the docker-msmtpd service. It utilizes external secrets for managing SMTP user and password securely. The configuration specifies the image, container name, port mapping, environment variables (referencing secret files), and a restart policy. It also defines the external secrets required for deployment. ```yaml name: msmtpd services: msmtpd: image: crazymax/msmtpd container_name: msmtpd ports: - target: 2500 published: 2500 protocol: tcp environment: - "TZ=Europe/Paris" - "PUID=1500" - "PGID=1500" - "SMTP_HOST=smtp.gmail.com" - "SMTP_PORT=587" - "SMTP_TLS=on" - "SMTP_STARTTLS=on" - "SMTP_TLS_CHECKCERT=on" - "SMTP_AUTH=on" - "SMTP_USER_FILE=/run/secrets/smtp_user" - "SMTP_PASSWORD_FILE=/run/secrets/smtp_password" - "SMTP_DOMAIN=localhost" secrets: - smtp_user - smtp_password restart: always secrets: smtp_user: external: true smtp_password: external: true ``` -------------------------------- ### Update Docker msmtpd Container Source: https://github.com/crazy-max/docker-msmtpd/blob/master/README.md Commands to update the msmtpd container when a new version is available. This involves pulling the latest image and then recreating the container to apply the update. It assumes Docker Compose is being used for management. ```bash docker compose pull docker compose up -d ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.