### Manual Installation of Docker SMTP Relay Source: https://github.com/turgon37/docker-smtp-relay/blob/master/README.md This code snippet shows the commands for manually cloning the project repository and building the Docker image using a provided build script. It's a prerequisite for manual deployment. ```bash git clone ./build.sh ``` -------------------------------- ### Automatic Installation of Docker SMTP Relay Source: https://github.com/turgon37/docker-smtp-relay/blob/master/README.md This command demonstrates how to automatically pull the pre-built Docker image for the SMTP relay service from Docker Hub. This is the simplest way to get started with the service. ```bash docker pull turgon37/smtp-relay ``` -------------------------------- ### Travis CI Integration Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt Example Travis CI configuration file (.travis.yml) demonstrating how to integrate the build, test, and publish scripts into a Continuous Integration pipeline. ```yaml # Travis CI integration (.travis.yml): # - Installs shellcheck # - Runs build.sh # - Runs tests.sh # - Runs publish.sh (only on non-PR commits) ``` -------------------------------- ### Basic Docker Run Command for SMTP Relay Source: https://github.com/turgon37/docker-smtp-relay/blob/master/README.md This example shows a basic command to run the SMTP relay service as a Docker container. It exposes port 25 and configures the relay domain. This is suitable for simple relay scenarios. ```bash docker run -p 25:25 -e "RELAY_MYDOMAIN=domain.com" -e "RELAY_HOST=relay:25" turgon37/smtp-relay ``` -------------------------------- ### Local SASL Password File Content Source: https://github.com/turgon37/docker-smtp-relay/blob/master/README.md This example shows the expected content of the local `sasl_passwd` file. This file is mounted into the Docker container to provide authentication credentials for the SMTP relay. The format specifies the target host and port, followed by the SASL username and password. ```bash user@host:~$ cat /my/local/path/sasl_passwd [10.1.0.1]:25 sasl-user-login:xxxxxxxxxxxx ``` -------------------------------- ### Test SMTP Relay Functionality with Python Client Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt This section provides examples of using the included Python SMTP client within a Docker container to test various relay functionalities. It covers unauthenticated sending, SASL authentication, STARTTLS encryption, SSL connections, custom headers, verbose debugging output, and testing failure scenarios like wrong credentials. The client requires specific arguments like sender, recipient, subject, body, and authentication details. ```bash # Simple unauthenticated test from trusted network docker exec smtp-relay /opt/smtp_client.py \ --from noreply@example.com \ --subject "Test Email" \ --body "This is a test message" \ recipient@example.com # Test with SASL authentication docker exec smtp-relay /opt/smtp_client.py \ --from john.doe@example.com \ --subject "Authenticated Test" \ --body "Testing SASL authentication" \ --user john.doe:SecurePassword123 \ external@otherdomain.com # Test with STARTTLS encryption docker exec smtp-relay /opt/smtp_client.py \ --from admin@example.com \ --subject "Encrypted Test" \ --body "Testing TLS encryption" \ --user admin.user:AdminPass789 \ --starttls \ secure@example.com # Test with SSL connection docker exec smtp-relay /opt/smtp_client.py \ --host smtp.gmail.com \ --port 465 \ --ssl \ --from user@example.com \ --subject "SSL Test" \ --user user@example.com:password \ recipient@gmail.com # Test with custom headers and multiple recipients docker exec smtp-relay /opt/smtp_client.py \ --from notifications@example.com \ --subject "System Alert" \ --body "Critical system notification" \ --header "X-Priority=1" \ --header "X-Mailer=Docker-SMTP-Relay" \ --user notifications:NotifyPass123 \ admin1@example.com admin2@example.com admin3@example.com # Test with verbose output for debugging docker exec smtp-relay /opt/smtp_client.py \ --from debug@example.com \ --subject "Debug Test" \ -vv \ --user debug:DebugPass \ test@example.com # Test failure scenario (wrong credentials) docker exec smtp-relay /opt/smtp_client.py \ --from user@example.com \ --subject "Auth Failure Test" \ --user wronguser:wrongpass \ recipient@example.com ``` -------------------------------- ### Configure Authenticated Relay with Persistence (YAML) Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt This Docker Compose configuration sets up a full-featured SMTP relay for production environments. It includes authenticated relay with TLS, persistent volumes for SASL data and mail queues, custom Postfix settings, and a health check. This example illustrates a robust deployment strategy for microservices requiring email functionality. ```yaml version: '3.8' services: smtp-relay: image: turgon37/smtp-relay:latest container_name: smtp-relay-prod restart: unless-stopped environment: # Basic configuration RELAY_POSTMASTER: 'postmaster@example.com' RELAY_MYHOSTNAME: 'smtp-relay.example.com' RELAY_MYDOMAIN: 'example.com' RELAY_MYNETWORKS: '127.0.0.0/8 10.0.0.0/24 172.16.0.0/16' # Upstream relay configuration RELAY_HOST: '[smtp.gmail.com]:587' RELAY_LOGIN: 'user@example.com' RELAY_PASSWORD: 'app-specific-password' # TLS configuration RELAY_USE_TLS: 'yes' RELAY_TLS_VERIFY: 'encrypt' RELAY_TLS_CA: '/etc/ssl/certs/ca-certificates.crt' # Relay mode and domain restriction RELAY_MODE: 'ALLOW_SASLAUTH_NODOMAIN' RELAY_STRICT_SENDER_MYDOMAIN: 'false' RELAY_DOMAINS: 'example.com example.org' # Custom Postfix settings via POSTCONF POSTCONF_compatibility_level: '2' POSTCONF_message_size_limit: '26214400' POSTCONF_mailbox_size_limit: '0' # Timezone TZ: 'America/New_York' ports: - "10.0.0.1:25:25" volumes: # Persistent SASL user database - smtp-sasl-data:/data # Persistent mail queue for retry handling - smtp-mail-queue:/var/spool/postfix # Optional: External SASL password file - ./sasl_passwd:/etc/postfix/sasl_passwd:ro # Optional: Sender address rewriting - ./sender_canonical:/etc/postfix/sender_canonical:ro healthcheck: test: ["CMD", "nc", "-znvw", "1", "127.0.0.1", "25"] interval: 30s timeout: 5s retries: 3 start_period: 10s volumes: smtp-sasl-data: driver: local smtp-mail-queue: driver: local # External sasl_passwd file format (./sasl_passwd): # [smtp.gmail.com]:587 user@example.com:app-specific-password # Expected behavior: # - Container starts and loads configuration # - SASL users can authenticate and relay to any domain # - Network 10.0.0.0/24 can relay to example.com/example.org only # - Mail queue persists across container restarts # - Maximum message size: 25MB ``` -------------------------------- ### Bulk User Registration for Docker SMTP Relay Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt This snippet demonstrates how to create a client_sasl_passwd file with user credentials and then run the Docker SMTP relay container, mounting this file for bulk user registration. It also shows how to verify that users have been successfully registered by checking the container logs. Ensure the path to the passwd file is correctly specified. ```bash cat > /tmp/client_sasl_passwd < large_body.txt # docker exec smtp-relay-custom /opt/smtp_client.py \ # --from sender@example.com \ # --subject "Large message test" \ # --body "$(cat large_body.txt)" \ # recipient@example.com ``` -------------------------------- ### Docker Command to List SASL Users Source: https://github.com/turgon37/docker-smtp-relay/blob/master/README.md This command executes a script inside the running `smtp-relay` Docker container to list all configured SASL users. It's a utility for verifying the current user database. ```bash docker exec smtp-relay /opt/listpasswd.sh ``` -------------------------------- ### Deploy SMTP Relay with Regex Rewriting Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt Deploys the SMTP relay container with support for regular expression-based sender rewriting. This enables more flexible and pattern-based sender address transformations. ```bash # For regex-based rewriting, use sender_canonical_classes: cat > sender_canonical_regex < sender_canonical < smtp-relay-logs-$(date +%Y%m%d).log # Monitor metrics with external tools docker stats smtp-relay ``` -------------------------------- ### SMTP Relay: Custom Postfix Restrictions Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt Configures a custom SMTP relay using Postfix restrictions, allowing fine-grained control over recipient domains via a Postfix lookup table. It permits SASL authenticated users and specific recipient domains, rejecting others. ```yaml services: smtp-custom: image: turgon37/smtp-relay:latest environment: RELAY_MYDOMAIN: 'example.com' RELAY_HOST: '[smtp.example.com]:587' RELAY_MODE: 'permit_sasl_authenticated, check_recipient_access hash:/etc/postfix/recipient_access, reject' POSTCONF_recipient_access: 'hash:/etc/postfix/recipient_access' volumes: - ./recipient_access:/etc/postfix/recipient_access:ro ports: - "25:25" ``` -------------------------------- ### Docker Compose for Complex SMTP Access Control Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt This configuration defines an SMTP relay service with advanced recipient and sender restrictions using Postfix directives. It mounts custom access control files for granular control over allowed and rejected domains/senders. Ensure 'recipient_access' and 'sender_access' files are present in the local directory. ```yaml services: smtp-complex-acl: image: turgon37/smtp-relay:latest environment: RELAY_MYDOMAIN: 'example.com' RELAY_HOST: '[smtp.example.com]:587' RELAY_MYNETWORKS: '10.0.0.0/24' # Complex recipient restrictions POSTCONF_smtpd_recipient_restrictions: | check_recipient_access hash:/etc/postfix/recipient_access, reject_non_fqdn_recipient, reject_unknown_recipient_domain, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination # Complex sender restrictions POSTCONF_smtpd_sender_restrictions: | check_sender_access hash:/etc/postfix/sender_access, reject_non_fqdn_sender, reject_unknown_sender_domain, permit volumes: - ./recipient_access:/etc/postfix/recipient_access:ro - ./sender_access:/etc/postfix/sender_access:ro ``` -------------------------------- ### SMTP Relay: Authenticated Users Unrestricted (Mode 4) Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt Sets up the SMTP relay to allow all SASL authenticated users and specified network ranges (e.g., 172.16.0.0/12) to send emails to any domain. All other senders are rejected. ```yaml services: smtp-open-relay: image: turgon37/smtp-relay:latest environment: RELAY_MYDOMAIN: 'example.com' RELAY_HOST: '[smtp.example.com]:587' RELAY_MODE: 'ALLOW_AUTH_NODOMAIN' RELAY_MYNETWORKS: '127.0.0.0/8 172.16.0.0/12' ports: - "25:25" ``` -------------------------------- ### SMTP Relay: Network Users Unrestricted (Mode 3) Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt Configures the SMTP relay to allow unrestricted sending for network users within specified networks (e.g., 192.168.1.0/24) and for SASL authenticated users to a specific domain (example.com). Other senders are rejected. ```yaml services: smtp-network-open: image: turgon37/smtp-relay:latest environment: RELAY_MYDOMAIN: 'example.com' RELAY_HOST: '[smtp.example.com]:587' RELAY_MODE: 'ALLOW_NETAUTH_NODOMAIN' RELAY_MYNETWORKS: '127.0.0.0/8 192.168.1.0/24' RELAY_DOMAINS: 'example.com' ports: - "25:25" ``` -------------------------------- ### Docker Compose for Unauthenticated SMTP Relay Source: https://github.com/turgon37/docker-smtp-relay/blob/master/README.md This Docker Compose configuration sets up an unauthenticated SMTP relay filtered by subnet and domain name. It specifies various environment variables for postmaster, hostname, domain, networks, and the relay host. ```yaml services: smtp-relay: image: turgon37/smtp-relay:latest environment: RELAY_POSTMASTER: 'postmaster@example.net' RELAY_MYHOSTNAME: 'smtp-relay.example.net' RELAY_MYDOMAIN: 'example.net' RELAY_MYNETWORKS: '127.0.0.0/8 10.0.0.0/24' RELAY_HOST: '[10.1.0.1]:25' ports: - "10.0.0.1:3000:25" ``` -------------------------------- ### Configure Network and Domain Restrictions - YAML Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt This YAML configuration sets up network-based access control and domain restrictions for the Docker SMTP Relay. It specifies allowed networks (RELAY_MYNETWORKS), relay domains (RELAY_DOMAINS), enforces strict sender domain checking (RELAY_STRICT_SENDER_MYDOMAIN), and configures Postfix sender restrictions (POSTCONF_smtpd_sender_restrictions). The service can also be configured to bind only to a specific network interface. ```yaml services: smtp-restricted: image: turgon37/smtp-relay:latest environment: RELAY_MYDOMAIN: 'example.com' RELAY_HOST: '[smtp.example.com]:587' # Allow multiple networks (space-separated) RELAY_MYNETWORKS: '127.0.0.0/8 10.0.0.0/24 192.168.1.0/24 172.16.0.0/12' # Restrict relay to specific domains RELAY_DOMAINS: 'example.com example.org partner.com' # Strict sender domain enforcement # Only allow senders from RELAY_MYDOMAIN RELAY_STRICT_SENDER_MYDOMAIN: 'true' # Relay mode RELAY_MODE: 'STRICT' # Reject non-FQDN senders POSTCONF_smtpd_sender_restrictions: 'reject_non_fqdn_sender, reject_unknown_sender_domain, permit' ports: - "10.0.0.1:25:25" # Only bind to specific network interface # Test network access from allowed network: # From 10.0.0.5: # telnet 10.0.0.1 25 # > EHLO test.local # > MAIL FROM: # > RCPT TO: # > DATA # > Subject: Test # > # > Test message # > . # > QUIT # Expected: 250 OK # Test from unauthorized network: # From 192.168.100.5: # telnet 10.0.0.1 25 # Connection refused or: # > RCPT TO: # Expected: 554 5.7.1 Relay access denied # Test strict sender domain enforcement: # docker exec smtp-restricted /opt/smtp_client.py \ # --from wrong@external.com \ # --subject "Wrong domain" \ # recipient@example.com # Expected error: # Error: unable to send email because of (554, b'5.7.1 Sender address rejected: Access denied') # Test allowed sender domain: ``` -------------------------------- ### SMTP Relay: TLS Security Configuration Source: https://context7.com/turgon37/docker-smtp-relay/llms.txt Configures the SMTP relay to use TLS encryption for upstream connections, with options for certificate validation and session caching. It specifies TLS verification levels and paths to CA certificates. ```yaml services: smtp-relay-tls: image: turgon37/smtp-relay:latest environment: RELAY_MYDOMAIN: 'example.com' RELAY_HOST: '[smtp.gmail.com]:587' RELAY_LOGIN: 'user@example.com' RELAY_PASSWORD: 'app-password' RELAY_USE_TLS: 'yes' RELAY_TLS_VERIFY: 'encrypt' RELAY_TLS_CA: '/etc/ssl/certs/ca-certificates.crt' POSTCONF_smtp_tls_security_level: 'encrypt' POSTCONF_smtp_tls_loglevel: '1' POSTCONF_smtp_tls_protocols: '!SSLv2,!SSLv3,!TLSv1,!TLSv1.1' POSTCONF_smtp_tls_ciphers: 'high' POSTCONF_smtp_tls_mandatory_ciphers: 'high' volumes: - ./custom-ca.crt:/etc/ssl/certs/custom-ca.crt:ro ports: - "25:25" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.