### Add Helm Repository and Install Postfix Chart Source: https://github.com/bokysan/docker-postfix/blob/master/README.md Add the Postfix Helm chart repository and then upgrade or install the chart. This example disables persistence and sets allowed sender domains to 'example.com'. ```shell helm repo add bokysan https://bokysan.github.io/docker-postfix/ helm upgrade --install --set persistence.enabled=false --set config.general.ALLOWED_SENDER_DOMAINS=example.com mail bokysan/mail ``` -------------------------------- ### Using Existing DKIM Keys Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/dkim-functions.md This example shows how to configure DKIM signing using pre-existing private and public key files. Ensure the keys are located at `/etc/opendkim/keys/{domain}.private` and `/etc/opendkim/keys/{domain}.txt`. ```bash # Pre-existing keys at: # /etc/opendkim/keys/example.com.private # /etc/opendkim/keys/example.com.txt export ALLOWED_SENDER_DOMAINS="example.com" postfix_setup_dkim # Configures DKIM using existing keys ``` -------------------------------- ### Example: Run container with JSON logging Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Demonstrates how to run a Postfix container with JSON-formatted syslog output enabled. ```bash docker run -e LOG_FORMAT=json boky/postfix # Produces: JSON-formatted syslog output ``` -------------------------------- ### HashFilter Query String Examples Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/email-anonymizer.md Provides examples of query strings for configuring the HashFilter. These demonstrate different combinations of parameters like salt, short_sha, prefix, split, and case_sensitive. ```text HashFilter?salt=my-secret-salt&short_sha=true&prefix=h: HashFilter?salt=org-salt&split=true&case_sensitive=false ``` -------------------------------- ### OpenDKIM Configuration Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/types.md A sample OpenDKIM configuration file showing common parameters for setting up signing and verification modes. ```ini Mode sv Socket inet:8891@127.0.0.1 PidFile /var/run/opendkim/opendkim.pid UserID opendkim:opendkim LogWhy no Syslog yes ``` -------------------------------- ### HashFilter Initialization Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/email-anonymizer.md Shows how to initialize the HashFilter with required and optional parameters. The 'salt' parameter is mandatory. ```python def init(self, args: 'dict[str, list[str]]') -> None: # Requires 'salt' parameter ``` -------------------------------- ### Example Host Connection to Submission Port Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/networking.md Example of connecting to the Postfix submission port (587) from the host machine using telnet. ```bash # From host: telnet localhost 587 # Response: 220 mail.example.com ESMTP Postfix ``` -------------------------------- ### Dockerfile Source Reference Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/README.md Illustrates how Dockerfile source locations are referenced, including file path and line numbers. ```dockerfile Dockerfile:66 ``` -------------------------------- ### Example: Warning Logged During Distribution Switch Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/database-upgrade-functions.md This is an example of a warning message logged by the postfix_upgrade_daemon_directory function when it detects a switch from Debian/Ubuntu to Alpine and is about to change the daemon_directory. ```bash WARN: You're switching from Debian/Ubuntu to Alpine. Changing daemon_directory... ``` -------------------------------- ### Postfix Main Configuration Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/types.md A sample of the Postfix main.cf configuration file, showing key-value pairs for hostname, networks, relay host, and SASL authentication. ```postfix myhostname = mail.example.com mynetworks = 127.0.0.0/8 10.0.0.0/8 relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes ``` -------------------------------- ### Example: Smart email anonymization Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Runs a Postfix container with 'smart' email anonymization enabled, showing the resulting log format. ```bash docker run -e ANONYMIZE_EMAILS=smart boky/postfix # Logs: user@example.com → u*r@*.com ``` -------------------------------- ### Auto-generate DKIM Keys Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/dkim-functions.md This example demonstrates how to auto-generate DKIM keys for specified domains. The function will create private and public key files and output the public key records for DNS configuration. ```bash export DKIM_AUTOGENERATE=1 export ALLOWED_SENDER_DOMAINS="example.com test.org" export DKIM_SELECTOR="example.com=mail,test.org=dkim" postfix_setup_dkim # Generates keys in /etc/opendkim/keys/ # Outputs public key records for DNS ``` -------------------------------- ### Email Anonymizer Filter Examples Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/email-anonymizer.md Provides examples of command-line invocations for different email anonymizer filters, including default, alias, paranoid, and hash filters with parameters. ```bash /scripts/email-anonymizer.py # SmartFilter (default) ``` ```bash /scripts/email-anonymizer.py default # SmartFilter (alias) ``` ```bash /scripts/email-anonymizer.py paranoid # ParanoidFilter ``` ```bash /scripts/email-anonymizer.py "HashFilter?salt=xyz" # HashFilter with parameters ``` -------------------------------- ### Example Usage of Logging Functions Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/utility-functions.md Demonstrates the usage of various logging functions with different severity levels and includes color variable usage. ```bash debug "Starting configuration" info "Hostname is ${emphasis}$HOSTNAME${reset}" notice "Using default network list" warn "SKIP_ROOT_SPOOL_CHOWN is set" error "Configuration failed" ``` -------------------------------- ### HashFilter Hashing Examples Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/email-anonymizer.md Demonstrates the output of the HashFilter with different configurations. Shows full hash, truncated hash, and separate hashing of local and domain parts. ```text salt="my-secret" user@example.com → a1b2c3d4e5f6g7h8i9j0... (full) user@example.com → a1b2c3d4 (with short_sha=true) split=true: local part (user) → hash1 domain part (example.com) → hash2 result → hash1@hash2 ``` -------------------------------- ### Standard Postfix Log (Raw) Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Example of a raw Postfix log entry including email addresses. ```log 2026-06-28T11:23:45.123456+00:00 mail postfix/smtp[12345]: ABCDEF: to=, relay=smtp.gmail.com[142.251.41.108]:587, delay=1.2, delays=0.1/0.2/0.5/0.4, dsn=2.0.0, status=sent (250 2.0.0 OK) ``` -------------------------------- ### Bash Script Source Reference Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/README.md Illustrates how bash script source locations are referenced, including file path and line numbers. ```bash image_root/scripts/functions.sh:123 ``` -------------------------------- ### Startup Sequence Functions Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/README.md Lists the sequence of functions executed during the startup of the Docker Postfix container. This sequence ensures all necessary setup steps are performed in the correct order. ```shell 1. announce_startup() 2. setup_timezone() 3. check_environment_sane() 4. rsyslog_log_format() 5. logrotate_remove_duplicate_mail_log() ... (31 more) 36. unset_sensitive_variables() ``` -------------------------------- ### Python Script Source Reference Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/README.md Illustrates how python script source locations are referenced, including file path and line numbers. ```python image_root/scripts/email-anonymizer.py:456 ``` -------------------------------- ### Python SMTP Client Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/networking.md Connect to the Postfix service from a Python application using its Kubernetes service DNS name. Ensure the application can resolve and reach the service. ```python # Python application import smtplib smtp = smtplib.SMTP('postfix-mail.default.svc.cluster.local', 587) ``` -------------------------------- ### Example: Debian to Alpine Daemon Directory Switch Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/database-upgrade-functions.md Illustrates the state of the daemon_directory configuration before and after the postfix_upgrade_daemon_directory function automatically updates it when switching from a Debian-based system to Alpine. ```bash # In /etc/postfix/main.cf (from Debian) daemon_directory = /usr/lib/postfix/sbin # Doesn't exist on Alpine ``` ```bash # Auto-updated by this function daemon_directory = /usr/libexec/postfix # Correct path for Alpine ``` -------------------------------- ### Example: Paranoid email anonymization Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Runs a Postfix container with 'paranoid' email anonymization enabled, showing the resulting log format. ```bash docker run -e ANONYMIZE_EMAILS=paranoid boky/postfix # Logs: user@example.com → *@*.com ``` -------------------------------- ### Mount Postfix Configuration Directory Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/networking.md Example of mounting the Postfix configuration directory to persist custom settings like main.cf and master.cf. It's advised to also keep the spool directory separate. ```bash docker run -v postfix_config:/etc/postfix boky/postfix ``` -------------------------------- ### Run Docker Postfix with Allowed Sender Domains Source: https://github.com/bokysan/docker-postfix/blob/master/README.md Use this command to run the Postfix Docker container, specifying allowed sender domains to prevent Postfix from refusing to start due to spam protection. Ensure to replace 'example.com' and 'example.org' with your actual domains. ```shell docker run --rm --name postfix -e "ALLOWED_SENDER_DOMAINS=example.com example.org" -p 1587:587 boky/postfix ``` -------------------------------- ### Basic Postfix Setup (Direct Delivery) Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/configuration.md Use this configuration for direct email delivery without any relay host. Ensure your server has a valid hostname and MX records. ```bash docker run -e ALLOWED_SENDER_DOMAINS="example.com" \ -p 1587:587 \ boky/postfix ``` -------------------------------- ### Example: Hash email anonymization with salt Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Runs a Postfix container with 'hash' email anonymization, including a custom salt and short SHA option. ```bash docker run -e ANONYMIZE_EMAILS="hash?salt=org-secret&short_sha=true" boky/postfix # Logs: user@example.com → a1b2c3d4 ``` -------------------------------- ### Example: No email anonymization Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Runs a Postfix container with anonymization disabled, showing that email addresses remain unchanged in logs. ```bash docker run -e ANONYMIZE_EMAILS=0 boky/postfix # Logs: user@example.com (unchanged) ``` -------------------------------- ### Execute Custom Postfix Configuration Source: https://github.com/bokysan/docker-postfix/blob/master/README.md Use shell scripts within `/docker-init.d/` to apply custom Postfix configurations. This example demonstrates enabling negative caching for address verification. ```shell #!/bin/sh postconf -e "address_verify_negative_cache=yes" ``` -------------------------------- ### Kubernetes StatefulSet for Postfix Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/networking.md Deploy Postfix as a StatefulSet in Kubernetes. This example configures environment variables for allowed sender domains and relay host, and sets up persistent storage for mail spool. ```yaml apiVersion: apps/v1 kind: StatefulSet metadata: name: postfix spec: serviceName: postfix-mail selector: matchLabels: app: postfix template: metadata: labels: app: postfix spec: containers: - name: postfix image: boky/postfix:latest ports: - containerPort: 587 env: - name: ALLOWED_SENDER_DOMAINS value: "example.com" - name: RELAYHOST value: "smtp.gmail.com:587" volumeMounts: - name: spool mountPath: /var/spool/postfix volumeClaimTemplates: - metadata: name: spool spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 5Gi ``` -------------------------------- ### OpenDKIM KeyTable Format Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/types.md Defines the format for the KeyTable file, mapping DKIM selectors and domains to their corresponding private key paths. Ensure the path to the private key is readable by the opendkim process. ```text selector._domainkey.domain.com domain:selector:/path/to/private.key mail._domainkey.example.com example.com:mail:/etc/opendkim/keys/example.com.private dkim._domainkey.test.org test.org:dkim:/etc/opendkim/keys/test.org.private ``` -------------------------------- ### Kubernetes Secrets Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/configuration.md Illustrates how to mount Kubernetes secrets as volumes and reference them using environment variables with the `_FILE` suffix. This allows sensitive data to be injected into the Postfix container securely. ```yaml containers: - name: postfix env: - name: RELAYHOST_PASSWORD_FILE value: /var/run/secrets/relay_password volumeMounts: - name: relay-secret mountPath: /var/run/secrets volumes: - name: relay-secret secret: secretName: relay-password ``` -------------------------------- ### Deploy Postfix with Helm Chart Source: https://github.com/bokysan/docker-postfix/blob/master/README.md Deploy the Postfix mail server using the Helm chart. This example disables persistence and allows empty sender domains. Refer to ArtifactHub for more configuration options. ```shell helm repo add bokysan https://bokysan.github.io/docker-postfix/ helm upgrade --install --set persistence.enabled=false --set config.general.ALLOW_EMPTY_SENDER_DOMAINS=yes mail bokysan/mail ``` -------------------------------- ### OpenDKIM SigningTable Format Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/types.md Illustrates the format for the SigningTable file, which associates email patterns with DKIM identities (selector._domainkey.domain) defined in the KeyTable. Use patterns like '*@domain.com' for broad matching or specific addresses. ```text *@domain.com selector._domainkey.domain.com *@example.com mail._domainkey.example.com *@test.org dkim._domainkey.test.org ``` -------------------------------- ### Run Container with Valid Timezone Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/errors.md Example of running the Postfix Docker container with a valid timezone specified. This resolves the 'Timezone Not Found' warning. ```bash docker run -e TZ="America/New_York" boky/postfix ``` -------------------------------- ### SmartFilter Example Usage with Query Parameter Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/email-anonymizer.md Demonstrates how to use the `mask_symbol` query parameter with `rsyslog` configuration to change the masking character from the default '*' to 'X'. ```bash rsyslog_config="... default?mask_symbol=X ..." # Outputs: d*o@*.org becomes dXo@*.org (uses X instead of *) ``` -------------------------------- ### Mount Postfix Spool Directory Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/networking.md Example of mounting the Postfix spool directory to preserve queued messages across container restarts. This is recommended for mail queue persistence. ```bash docker run -v postfix_spool:/var/spool/postfix boky/postfix ``` -------------------------------- ### Docker Compose for Inbound Connections Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/networking.md Example Docker Compose configuration to set up Postfix and an application service on the same network, allowing inbound connections to Postfix on port 587. ```yaml services: app: image: myapp networks: - mail-network # Same network as Postfix postfix: image: boky/postfix environment: ALLOWED_SENDER_DOMAINS: example.com networks: - mail-network ports: - "587:587" networks: mail-network: ``` -------------------------------- ### Setup External SMTP Relay Host Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/postfix-configuration-functions.md Configures an external SMTP relay host, including authentication details. Supports Docker Secrets for password management. ```bash postfix_setup_relayhost() ``` ```bash export RELAYHOST="smtp.gmail.com:587" export RELAYHOST_USERNAME="user@example.com" export RELAYHOST_PASSWORD="app-password" postfix_setup_relayhost # Configures Gmail relay with authentication ``` -------------------------------- ### Mount OpenDKIM Keys Directory Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/networking.md Example of mounting the OpenDKIM keys directory to preserve DKIM private and public keys. Ensure private keys are never exposed outside the container. ```bash docker run -v dkim_keys:/etc/opendkim/keys boky/postfix ``` -------------------------------- ### Setup Timezone from TZ Variable Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Configures the container's timezone based on the `TZ` environment variable. Creates symlinks and sets the timezone file, warning if the timezone file is not found. ```bash export TZ="Europe/Amsterdam" setup_timezone() ``` -------------------------------- ### announce_startup() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Prints a startup banner with system and account information. It detects the distribution and displays UIDs/GIDs for postfix and opendkim accounts. ```APIDOC ## announce_startup() ### Description Prints a startup banner with system and account information. It detects the distribution and displays UIDs/GIDs for postfix and opendkim accounts. ### Method Shell command ### Endpoint announce_startup() ### Parameters None ### Response None (prints to stdout) ### Output Example: ``` ★★★★★ POSTFIX STARTING UP (alpine) ★★★★★ System accounts: postfix=101:104, opendkim=102:105 ``` ``` -------------------------------- ### Postfix XOAuth2 Post-Configuration Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/authentication-functions.md Configures the XOAuth2 SASL mechanism in Postfix after initial setup. It detects installed SASL plugins and adjusts the mechanism list if XOAuth2 is not enabled. ```bash postfix_setup_xoauth2_post_setup() ``` -------------------------------- ### setup_conf() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Copies initial Postfix configuration from /etc/postfix.template/ to /etc/postfix/ if the destination does not exist. It ensures that custom configurations are preserved by not overwriting existing files. ```APIDOC ## setup_conf() ### Description Copies initial Postfix configuration from `/etc/postfix.template/` to `/etc/postfix/` if the destination directory does not exist. This function ensures that custom configurations are preserved by not overwriting existing files. ### Parameters None ### Returns None ### Behavior - Recursively copies missing files/directories from `/etc/postfix.template/` to `/etc/postfix/`. - Does not overwrite existing files. - Creates `/etc/postfix/` directory if it is missing. ``` -------------------------------- ### Docker Secrets Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/configuration.md Demonstrates how to use Docker secrets to provide sensitive variables like passwords to the Postfix container. The `_FILE` suffix indicates that the variable's value should be read from the specified file path. ```bash docker run --secret relay_password \ -e RELAYHOST_PASSWORD_FILE=/run/secrets/relay_password \ -e RELAYHOST="smtp.gmail.com:587" \ boky/postfix ``` -------------------------------- ### Postfix Recipient Restrictions Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/types.md An example of how to integrate the allowed senders check into Postfix's main configuration. ```postfix smtpd_recipient_restrictions = reject_non_fqdn_recipient, reject_unknown_recipient_domain, check_sender_access lmdb:/etc/postfix/allowed_senders, reject ``` -------------------------------- ### Initialization Functions Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/MANIFEST.txt Reference for 14 startup initialization functions used to set up the Postfix service. ```APIDOC ## Initialization Functions ### Description Provides documentation for 14 functions related to the startup and initialization of the Docker Postfix service. ### Usage Refer to `api-reference/initialization-functions.md` for detailed function signatures, parameters, and examples. ``` -------------------------------- ### Email Anonymizer Filter Validation Examples Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/email-anonymizer.md Shows examples of valid and invalid filter class names that the email anonymizer script accepts or rejects to prevent injection vulnerabilities. ```python # Valid: "SmartFilter" "custom_filter.MyFilter" ``` ```python # Invalid (rejected): "__import__(...)" "os.system(...)" ``` -------------------------------- ### Enable Postfix Chroot Environment Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Prepares the filesystem for a Postfix chroot environment by copying necessary configuration files and directories. It handles the creation of `/etc/nsswitch.conf` if it's missing, addressing potential issues in containerized environments like Kubernetes. ```bash postfix_enable_chroot() ``` -------------------------------- ### postfix_enable_chroot() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Prepares the filesystem for the Postfix chroot environment by copying necessary configuration files and directories. It also handles the creation of `/etc/nsswitch.conf` to resolve Kubernetes-specific issues. ```APIDOC ## postfix_enable_chroot() ### Description Prepares the filesystem for the Postfix chroot environment. This function copies essential configuration files and directories into the chroot jail, ensuring Postfix operates correctly in an isolated environment. ### Parameters #### Environment Variables - **$POSTFIXD_DIR** (string) - Optional - Defaults to `/var/spool/postfix`. Specifies the Postfix spool directory. - **$POSTFIXD_ETC** (string) - Optional - Defaults to `$POSTFIXD_DIR/etc`. Specifies the chroot `/etc` directory. - **$POSTFIXD_ZIF** (string) - Optional - Defaults to `$POSTFIXD_DIR/usr/share/zoneinfo`. Specifies the chroot timezone directory. ### Returns None ### Files Copied into Chroot - `/etc/localtime` - `/etc/nsswitch.conf` (created if missing, fixes Kubernetes issue #71082) - `/etc/resolv.conf` - `/etc/services` - `/etc/host.conf` - `/etc/hosts` - `/etc/passwd` - `/usr/share/zoneinfo/` (all timezones) ### Creates - `/etc/nsswitch.conf` with content `hosts: files dns` if missing. ``` -------------------------------- ### DKIM Functions Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/MANIFEST.txt Guides on DKIM key generation and OpenDKIM configuration. ```APIDOC ## DKIM Functions ### Description Provides functions and instructions for generating DKIM keys and configuring OpenDKIM for email signing. ### Usage Refer to `api-reference/dkim-functions.md` for detailed guidance on DKIM setup. ``` -------------------------------- ### Announce Startup Banner Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Prints a startup banner with system and account details. Detects the distribution and displays UIDs/GIDs for Postfix and OpenDKIM. ```bash announce_startup() ``` -------------------------------- ### Check Postfix Startup Errors Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/errors.md Review the container's general logs to identify any errors that occurred during the Postfix service startup. ```bash docker logs ``` -------------------------------- ### Create and Initialize Postfix Aliases Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Creates an empty alias file and generates the binary database. This function is primarily for Postfix validation purposes. ```bash postfix_create_aliases() ``` -------------------------------- ### postfix_setup_xoauth2_post_setup() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/authentication-functions.md Post-configures the XOAuth2 SASL mechanism in Postfix. This function does not take any parameters and relies on settings from `postfix_setup_xoauth2_pre_setup()`. It adjusts SASL configuration based on whether XOAuth2 is enabled and handles different distribution naming conventions. ```APIDOC ## postfix_setup_xoauth2_post_setup() ### Description Post-configures XOAuth2 SASL mechanism in Postfix. It detects installed SASL plugins and adjusts the mechanism list if XOAuth2 is not enabled, ensuring proper handling of credentials. ### Method None (Shell function) ### Parameters None ### Behavior - Detects installed SASL plugins. - Removes sasl-xoauth2 from mechanism list if XOAuth2 is not enabled. - Handles different distro naming conventions. ### Postfix Configuration Set (when XOAuth2 enabled) ``` smtp_sasl_security_options = (empty) smtp_sasl_mechanism_filter = xoauth2 smtp_tls_session_cache_database = lmdb:${data_directory}/smtp_scache ``` ### Postfix Configuration Set (when XOAuth2 disabled) ``` smtp_sasl_mechanism_filter = [list of other mechanisms excluding xoauth2] ``` ``` -------------------------------- ### Postfix Log (Anonymized - Hash) Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Example of a Postfix log entry anonymized using the 'hash' format, replacing email addresses with hashes. ```log 2026-06-28T11:23:45.123456+00:00 mail postfix/smtp[12345]: ABCDEF: to=, relay=smtp.gmail.com[142.251.41.108]:587, delay=1.2, delays=0.1/0.2/0.5/0.4, dsn=2.0.0, status=sent (250 2.0.0 OK) ``` -------------------------------- ### postfix_setup_xoauth2_pre_setup() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/authentication-functions.md Pre-configures XOAuth2 authentication for relay hosts like Gmail and Google Workspace. It sets up necessary configuration files and token storage for secure authentication. ```APIDOC ## postfix_setup_xoauth2_pre_setup() ### Description Pre-configures XOAuth2 authentication for relay hosts (Gmail, Google Workspace). ### Method Shell Function ### Parameters #### Environment Variables - **$XOAUTH2_CLIENT_ID** (string) - Conditional - OAuth2 client ID from Google Cloud Console - **$XOAUTH2_SECRET** (string) - Conditional - OAuth2 client secret - **$XOAUTH2_TOKEN_ENDPOINT** (string) - No - `https://accounts.google.com/o/oauth2/token` - Google OAuth2 token endpoint - **$XOAUTH2_INITIAL_ACCESS_TOKEN** (string) - Conditional - Initial access token (only needed on first run) - **$XOAUTH2_INITIAL_REFRESH_TOKEN** (string) - Conditional - Initial refresh token (only needed on first run) - **$XOAUTH2_SYSLOG_ON_FAILURE** (string) - No - `no` - Log failures to syslog - **$XOAUTH2_FULL_TRACE** (string) - No - `no` - Log full trace on failure - **$RELAYHOST** (string) - Required - Relay host (e.g., `smtp.gmail.com:587`) - **$RELAYHOST_USERNAME** (string) - Required - Gmail address or service account email ### Returns None ### Files Created - `/etc/sasl-xoauth2.conf` — OAuth2 configuration (JSON format) - `/var/spool/postfix/xoauth2-tokens/$RELAYHOST_USERNAME` — Token file (JSON) ### Token File Format ```json { "access_token": "...", "refresh_token": "...", "expiry": "0" } ``` ### Errors - Exits if `$RELAYHOST` or `$RELAYHOST_USERNAME` not set ### Example ```bash export XOAUTH2_CLIENT_ID="123456789.apps.googleusercontent.com" export XOAUTH2_SECRET="your-secret-key" export XOAUTH2_INITIAL_ACCESS_TOKEN="initial-access-token" export XOAUTH2_INITIAL_REFRESH_TOKEN="initial-refresh-token" export RELAYHOST="smtp.gmail.com:587" export RELAYHOST_USERNAME="user@gmail.com" postfix_setup_xoauth2_pre_setup ``` ``` -------------------------------- ### Postfix Log (Anonymized - Paranoid) Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Example of a Postfix log entry anonymized using the 'paranoid' format, completely masking email addresses. ```log 2026-06-28T11:23:45.123456+00:00 mail postfix/smtp[12345]: ABCDEF: to=<*@*.com>, relay=smtp.gmail.com[142.251.41.108]:587, delay=1.2, delays=0.1/0.2/0.5/0.4, dsn=2.0.0, status=sent (250 2.0.0 OK) ``` -------------------------------- ### Postfix Log (Anonymized - Smart) Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/logging-functions.md Example of a Postfix log entry anonymized using the 'smart' format, partially masking email addresses. ```log 2026-06-28T11:23:45.123456+00:00 mail postfix/smtp[12345]: ABCDEF: to=, relay=smtp.gmail.com[142.251.41.108]:587, delay=1.2, delays=0.1/0.2/0.5/0.4, dsn=2.0.0, status=sent (250 2.0.0 OK) ``` -------------------------------- ### Kubernetes Service Definition for Postfix Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/networking.md Define a Kubernetes Service to expose your Postfix deployment. This example uses a static cluster IP, which is optional. ```yaml apiVersion: v1 kind: Service metadata: name: postfix-mail spec: selector: app: postfix ports: - protocol: TCP port: 587 targetPort: 587 name: submission clusterIP: 10.0.0.50 # Static IP optional ``` -------------------------------- ### HashFilter Replacement Method Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/email-anonymizer.md Illustrates the replace method of HashFilter, which generates the hashed email string. It uses HMAC-SHA256 with a user-provided salt. ```python def replace(self, match: re.match, msg: str) -> str: return self.prefix + hash + self.suffix ``` -------------------------------- ### execute_post_init_scripts() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Executes custom initialization scripts located in `/docker-init.d/` and `/docker-init.db/` directories. Supports sourcing environment variables for `.sh` files and executing others with `bash`. ```APIDOC ## execute_post_init_scripts() ### Description Executes custom initialization scripts from `/docker-init.d/` and `/docker-init.db/` directories. ### Method Shell Function ### Signature execute_post_init_scripts() ### Parameters None ### Returns None ### Script Directories - `/docker-init.d/` — Recommended mount point for custom scripts - `/docker-init.db/` — Legacy mount point (deprecated, shows warning) ### Script Execution - Executable `.sh` files are sourced (inherit environment) - Non-executable `.sh` files are executed with `bash` - Other files are ignored ### Example Script ```bash # Custom init script at /docker-init.d/my-setup.sh #!/bin/bash do_postconf -e "my_custom_param=value" ``` ``` -------------------------------- ### DKIM Selector Configuration Example Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/dkim-functions.md Defines custom DKIM selectors for specific domains. If a domain is not explicitly listed, a default selector is used. ```bash export DKIM_SELECTOR="gmail.com=google,yahoo.com=yahoo,mail" # gmail.com uses 'google', yahoo.com uses 'yahoo', others use 'mail' ``` -------------------------------- ### postfix_setup_dkim() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/dkim-functions.md Configures DKIM signing for allowed sender domains. It can auto-generate missing keys or use existing ones, and sets up Postfix to use OpenDKIM for signing. ```APIDOC ## postfix_setup_dkim() ### Description Configures DKIM signing for allowed sender domains. It can auto-generate missing keys or use existing ones, and sets up Postfix to use OpenDKIM for signing. ### Function Signature ```bash postfix_setup_dkim() ``` ### Parameters #### Environment Variables - **DKIM_AUTOGENERATE** (string) - Optional - Set to non-empty to auto-generate missing keys. - **ALLOWED_SENDER_DOMAINS** (string) - Conditional - Domains to create DKIM keys for (required if `DKIM_AUTOGENERATE` is set). - **DKIM_SELECTOR** (string) - Optional - Custom DKIM selector(s) per domain. Format: `domain.com=selector1,example.org=selector2,default_selector` or a bare value for the default selector. ### Returns None ### Behavior Details **Auto-Generation (when `$DKIM_AUTOGENERATE` is set):** - Creates `/etc/opendkim/keys/` directory if missing. - For each domain in `$ALLOWED_SENDER_DOMAINS`, checks for `/etc/opendkim/keys/{domain}.private`. - If missing, generates a 2048-bit RSA key using `opendkim-genkey`. - Fixes hash algorithm header to `h=sha256`. - Sets permissions: private key `400`, public key `644`. - Displays public key content for DNS configuration. **DKIM Configuration (when keys exist):** - Creates `/var/run/opendkim/` directory. - Detects OpenDKIM socket from `/etc/opendkim/opendkim.conf`. - Converts socket format to Postfix milter format. - Sets Postfix milter configuration (`milter_protocol`, `milter_default_action`, `smtpd_milters`, `non_smtpd_milters`). - Creates OpenDKIM databases: `/etc/opendkim/TrustedHosts`, `/etc/opendkim/KeyTable`, `/etc/opendkim/SigningTable`. ### Key Files Created - `/etc/opendkim/keys/{domain}.private` (RSA private key, owner: `opendkim:opendkim`) - `/etc/opendkim/keys/{domain}.txt` (DKIM public key record in DNS format) ### Example Usage **Auto-generate keys:** ```bash export DKIM_AUTOGENERATE=1 export ALLOWED_SENDER_DOMAINS="example.com test.org" export DKIM_SELECTOR="example.com=mail,test.org=dkim" postfix_setup_dkim ``` **Using existing keys:** ```bash export ALLOWED_SENDER_DOMAINS="example.com" postfix_setup_dkim ``` ### DNS Configuration Required For each domain, add a TXT record similar to: ``` mail._domainkey.example.com. IN TXT "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0..." ``` ``` -------------------------------- ### postfix_create_aliases() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Creates and initializes the Postfix alias database by generating an empty alias file and then running `postalias` to create the binary database. ```APIDOC ## postfix_create_aliases() ### Description Creates and initializes the Postfix alias database. This involves creating an empty `/etc/postfix/aliases` file and then running `postalias` to generate the binary database. While the database is not directly used by this image, it is required for Postfix validation. ### Method Shell Function ### Parameters None ### Returns None ``` -------------------------------- ### Initialize Postfix Configuration Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Copies initial Postfix configuration files from a template directory to the main configuration directory if the destination does not already exist. This function ensures that default configurations are present without overwriting user-defined settings. ```bash setup_conf() ``` -------------------------------- ### DKIM Selector Configuration Examples Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/configuration.md Configure DKIM selectors for domain-specific or general use. The `DKIM_SELECTOR` variable accepts a comma-separated list of domain-selector pairs or a single selector for all domains. ```bash DKIM_SELECTOR="mail" ``` ```bash DKIM_SELECTOR="example.com=google,test.org=dkim,mail" ``` -------------------------------- ### DNS Configuration for DKIM Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/dkim-functions.md This is an example of the TXT record required in your DNS settings for DKIM to function correctly. Replace the public key 'p=' value with the actual key generated. ```dns mail._domainkey.example.com. IN TXT "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0..." ``` -------------------------------- ### Execute Post-Initialization Scripts Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/initialization-functions.md Executes custom initialization scripts located in /docker-init.d/ and /docker-init.db/. Supports sourcing executable .sh files and executing non-executable .sh files with bash. ```bash execute_post_init_scripts() ``` ```bash # Custom init script at /docker-init.d/my-setup.sh #!/bin/bash do_postconf -e "my_custom_param=value" ``` -------------------------------- ### Get Postfix Configuration Parameter Value Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/utility-functions.md Use `get_postconf` to retrieve the value of a Postfix configuration parameter. It returns the value to stdout and handles cases where the parameter might not exist. ```bash host=$(get_postconf "myhostname") echo "Postfix hostname: $host" size_limit=$(get_postconf "message_size_limit") if [[ "$size_limit" == "0" ]]; then echo "Message size: unlimited" fi ``` -------------------------------- ### postfix_setup_debugging() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/postfix-configuration-functions.md Enables verbose debugging for SMTP connections originating from networks defined in `$POSTFIX_mynetworks`. This function modifies Postfix and OpenDKIM configurations to produce detailed SMTP connection logs when the `INBOUND_DEBUGGING` environment variable is set. ```APIDOC ## postfix_setup_debugging() ### Description Enables verbose debugging for SMTP connections from specified networks. This function sets up detailed logging for Postfix and OpenDKIM when the `INBOUND_DEBUGGING` environment variable is active. ### Method Shell Function ### Parameters #### Environment Variables - **INBOUND_DEBUGGING** (string) - Optional - Set to any value to enable debugging. ### Behavior - Sets `debug_peer_list` to the value of `$POSTFIX_mynetworks`. - Enables `LogWhy yes` in OpenDKIM configuration. - Produces verbose SMTP connection logs. ### Example ```bash export INBOUND_DEBUGGING=1 postfix_setup_debugging # Enables debugging for all trusted networks ``` ``` -------------------------------- ### Run Postfix with Authenticated Relay Host Source: https://github.com/bokysan/docker-postfix/blob/master/README.md Configure Postfix to use a relay host that requires username and password authentication. Provide credentials using environment variables. ```shell docker run --rm --name postfix -e RELAYHOST=mail.google.com -e RELAYHOST_USERNAME=hello@gmail.com -e RELAYHOST_PASSWORD=world -p 1587:587 boky/postfix ``` -------------------------------- ### Get DKIM Selector for Domain Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/dkim-functions.md Parses DKIM selector configuration for a given domain. It checks the DKIM_SELECTOR environment variable for domain-specific mappings and falls back to a default or a system default. ```bash get_dkim_selector() DOMAIN ``` ```bash export DKIM_SELECTOR="example.com=mail,test.org=dkim,default" get_dkim_selector "example.com" # Output: mail get_dkim_selector "test.org" # Output: dkim get_dkim_selector "other.com" # Output: default get_dkim_selector "nothing.com" # Output: default # Reset selector unset DKIM_SELECTOR get_dkim_selector "anything.com" # Output: mail ``` -------------------------------- ### Apply Custom Postfix Commands Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/postfix-configuration-functions.md Applies arbitrary Postfix configuration parameters using environment variables. Set environment variables prefixed with POSTFIX_ to configure specific Postfix settings. An empty value deletes the parameter. ```bash postfix_custom_commands() ``` ```bash export POSTFIX_maximal_queue_lifetime=5d export POSTFIX_bounce_queue_lifetime=3d postfix_custom_commands() # Sets maximal_queue_lifetime and bounce_queue_lifetime ``` -------------------------------- ### Postfix Configuration Functions Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/MANIFEST.txt Details on 13 functions for configuring Postfix parameters within the Docker image. ```APIDOC ## Postfix Configuration Functions ### Description Documentation for 13 functions that allow for the configuration of various Postfix parameters. ### Usage Consult `api-reference/postfix-configuration-functions.md` for a complete list of functions, their parameters, and usage examples. ``` -------------------------------- ### postfix_custom_commands() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/postfix-configuration-functions.md Applies arbitrary Postfix configuration parameters dynamically through environment variables. Any environment variable prefixed with `POSTFIX_` will be processed, allowing for flexible configuration adjustments. ```APIDOC ## postfix_custom_commands() ### Description Applies arbitrary Postfix configuration parameters via environment variables. This function allows users to set or delete Postfix configuration options by defining environment variables prefixed with `POSTFIX_`. ### Method Shell Function ### Parameters #### Environment Variables - **POSTFIX_*** (string) - Optional - Any environment variable starting with `POSTFIX_` will be processed. The prefix `POSTFIX_` is removed to determine the configuration parameter name. ### Behavior - Iterates through all environment variables starting with `POSTFIX_`. - Extracts the configuration parameter name by removing the `POSTFIX_` prefix. - Sets the configuration parameter in Postfix. If the environment variable's value is empty, the parameter is deleted from the Postfix configuration. ### Example ```bash export POSTFIX_maximal_queue_lifetime=5d export POSTFIX_bounce_queue_lifetime=3d postfix_custom_commands # Sets maximal_queue_lifetime and bounce_queue_lifetime ``` ``` -------------------------------- ### Run Docker Postfix for Simple Relay (Gmail) Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/INDEX.md Use this command to configure the Postfix container to relay emails through Gmail using standard SMTP authentication. Ensure you have an app-specific password for your Gmail account. ```bash docker run -e ALLOWED_SENDER_DOMAINS="example.com" \ -e RELAYHOST="smtp.gmail.com:587" \ -e RELAYHOST_USERNAME="user@gmail.com" \ -e RELAYHOST_PASSWORD="app-password" \ -p 1587:587 \ boky/postfix ``` -------------------------------- ### Run Postfix Container with Mounted DKIM Keys Source: https://github.com/bokysan/docker-postfix/blob/master/README.md This command runs the Postfix Docker container, mounting a local directory containing DKIM keys to the container's OpenDKIM key directory. It also specifies allowed sender domains. ```shell docker run --rm --name postfix -e "ALLOWED_SENDER_DOMAINS=example.com example.org" -v /host/keys:/etc/opendkim/keys -p 1587:587 boky/postfix ``` -------------------------------- ### Run Postfix with Relay Host Source: https://github.com/bokysan/docker-postfix/blob/master/README.md Use this command to run the Postfix container and relay all outgoing emails through a specified host. Ensure the container is mapped to the correct port. ```shell docker run --rm --name postfix -e RELAYHOST=192.168.115.215 -p 1587:587 boky/postfix ``` -------------------------------- ### Run Postfix Container with Docker Source: https://github.com/bokysan/docker-postfix/blob/master/README.md Use this command to run the Postfix container with specified environment variables and port mapping. Ensure your outgoing port 25 is not blocked by your ISP. ```shell docker run --rm --name postfix -e "ALLOWED_SENDER_DOMAINS=example.com" -p 1587:587 boky/postfix ``` -------------------------------- ### Override Postfix Configuration Settings Source: https://github.com/bokysan/docker-postfix/blob/master/README.md Any Postfix configuration option can be overridden using POSTFIX_ environment variables. For example, POSTFIX_allow_mail_to_commands can be set to control mail delivery commands. An empty variable removes the setting. ```shell docker run --rm --name postfix -e "POSTFIX_allow_mail_to_commands=alias,forward,include" -p 1587:587 boky/postfix ``` -------------------------------- ### Postfix SMTP Submission Port Authentication Setup Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/authentication-functions.md Sets up SMTP submission port authentication for client access using SASLDB2. This function creates necessary configuration files and SASL users when the SMTPD_SASL_USERS variable is defined. ```bash postfix_setup_smtpd_sasl_auth() ``` ```bash export SMTPD_SASL_USERS="user1@example.com:password1,user2@example.com:password2" postfix_setup_smtpd_sasl_auth # Creates SASL users for submission port access ``` -------------------------------- ### postfix_upgrade_conf() Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/api-reference/database-upgrade-functions.md Migrates legacy database references (e.g., `hash:`, `btree:`) in `/etc/postfix/main.cf` to the modern LMDB format. It identifies and regenerates affected database files using `postalias` or `postmap`. ```APIDOC ## postfix_upgrade_conf() ### Description Migrates legacy database references (e.g., `hash:`, `btree:`) in `/etc/postfix/main.cf` to the modern LMDB format. This function scans the configuration file, replaces old prefixes with `lmdb:`, and regenerates the affected database files using `postalias` or `postmap` as appropriate. It handles multi-line entries, duplicates, and missing files, and continues operation even if some database regenerations fail. ### Function Signature ```bash postfix_upgrade_conf() ``` ### Parameters None ### Returns None ### Target File `/etc/postfix/main.cf` ### Behavior 1. Scans `/etc/postfix/main.cf` for lines containing `hash:` or `btree:` prefixes. 2. Replaces these prefixes with `lmdb:`. 3. Identifies database files that need regeneration based on whether they are alias maps or other map types. 4. Regenerates affected databases using `postalias` (for alias maps) or `postmap` (for other map types). ### Example Configuration Changes **Before:** ``` virtual_mailbox_maps = hash:/etc/postfix/virtual transport_maps = btree:/etc/postfix/transport alias_maps = hash:/etc/postfix/aliases ``` **After:** ``` virtual_mailbox_maps = lmdb:/etc/postfix/virtual transport_maps = lmdb:/etc/postfix/transport alias_maps = lmdb:/etc/postfix/aliases ``` ### Commands Executed (Examples) ```bash postmap lmdb:/etc/postfix/virtual # Regenerate virtual database postmap lmdb:/etc/postfix/transport # Regenerate transport database postalias lmdb:/etc/postfix/aliases # Regenerate aliases ``` ### Edge Cases Handled - **Multi-line entries:** Uses `sed` to correctly handle entries that span multiple lines. - **Duplicates:** Deduplicates database entries before regeneration. - **Missing files:** Skips regeneration for source files that do not exist. ### Error Handling - The function continues execution even if individual database regeneration commands fail. - It does not exit the script on errors related to specific databases. ### Use Cases - **Migrating from Debian to Alpine:** Addresses the removal of `hash:` support in Alpine. - **Updating Postfix versions:** Modernizes configurations that use older database types. - **Persisted configuration volumes:** Fixes incompatible configurations loaded from older image versions. ``` -------------------------------- ### Access Mail Service via NodePort Source: https://github.com/bokysan/docker-postfix/blob/master/helm/mail/templates/NOTES.txt Use this snippet to get the NodePort and Node IP to access the mail service when service type is NodePort. It exports variables for the Node Port and Node IP, then prints the access URL. ```bash {{- if contains "NodePort" .Values.service.type }} export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "mail.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT {{- end }} ``` -------------------------------- ### Run Docker Postfix with DKIM and Inbound Auth Source: https://github.com/bokysan/docker-postfix/blob/master/_autodocs/INDEX.md Set up the Postfix container with DKIM auto-generation and inbound SMTP authentication using SASL users. This requires mounting volumes for DKIM keys and Postfix spool. ```bash docker run -e ALLOWED_SENDER_DOMAINS="example.com" \ -e RELAYHOST="smtp.gmail.com:587" \ -e RELAYHOST_USERNAME="user@gmail.com" \ -e RELAYHOST_PASSWORD="password" \ -e DKIM_AUTOGENERATE=1 \ -e SMTPD_SASL_USERS="app@example.com:apppass" \ -v postfix_keys:/etc/opendkim/keys \ -v postfix_spool:/var/spool/postfix \ -p 1587:587 \ boky/postfix ```