OneLinersCommand workbench
Guides
Services & Applications / Networking & DNS

Configure Postfix as an internet mail server

Set canonical identity, destinations, trusted networks, relay restrictions, DNS, TLS, aliases, logging, and end-to-end tests without becoming an open relay.

90 min8 stepsChanges system stateRevision 2
Save or explore
Save to collectionCreate a collection in the sidebar first.
0 of 8 steps completed
Goal

Receive mail for owned domains and deliver outbound mail directly with a minimal, auditable Postfix configuration.

Supported environments
  • Postfix 3.8+
Prerequisites
  • Authoritative DNS and stable identity Control forward and reverse DNS, choose the canonical mail hostname and domains, and verify the host is not behind an outbound SMTP-blocking network.hostname -f; getent ahosts $(hostname -f); dig +short -x {{publicIp}}
  • Recovery and queue safety Keep console access, back up active configuration, and record queue state before changing routing, authentication, filters, or mailbox delivery.
  • Abuse and deliverability plan Define relay boundaries, account owners, rate limits, bounce handling, postmaster address, monitoring, and how compromised credentials will be revoked.
Operating boundary

OneLiners never runs these steps or stores secrets. Review placeholders, versions, current state, and change-control requirements before using a command.

Full guide

What you will build

System
  • A production Postfix implementation of “Configure Postfix as an internet mail server” with explicit SMTP/IMAP boundaries, identity, durable state and observable delivery evidence.
  • A read-only baseline, staged candidate and end-to-end canary covering DNS, TLS, authentication, recipient or route policy, queue/mailbox state and logs.
  • A security and rollback procedure that avoids open relay, backscatter, plaintext credentials, world-readable keys/mail and unreviewed bulk queue actions.
Observable outcome
  • Receive mail for owned domains and deliver outbound mail directly with a minimal, auditable Postfix configuration. The intended success path is visible in native status, protocol transcript, headers or mailbox evidence.
  • Expected unauthorized relay, unknown-recipient, wrong-sender, invalid-authentication or wrong-certificate tests fail at the declared boundary without harming unrelated mail.

Architecture

How the parts fit together

The public MTA accepts SMTP on port 25 for domains it is authoritative for, performs recipient and policy checks before queue acceptance, and resolves remote MX records for outbound delivery. A stable PTR/A/AAAA identity, restricted relay policy, local queue and structured logs are operational dependencies. Submission and mailbox access remain separate services. The tutorial proves inbound/local/outbound paths with controlled addresses while preserving a configuration and queue baseline for rollback.

SMTP listenersAccept server-to-server mail only under explicit recipient and relay policy.
Router/transportResolve local delivery or remote MX destinations.
Queue and retryDurably hold accepted messages and record delivery diagnostics.
DNS and logsEstablish public identity and make each delivery decision observable.
  1. Inventory hostname/DNS, listeners, certificates, identities, recipient/relay maps, queue/mailbox state, logs and a recoverable configuration/data baseline.
  2. Prepare the internet mta candidate with official Postfix syntax, protected secrets and one explicit service/data boundary at a time.
  3. Run native configuration validation and immediate read-only checkpoint before reload or acceptance of new messages.
  4. Use controlled local and external canaries plus an expected-denial test, preserve message identifiers/headers, and retain the prior configuration for rollback.

Assumptions

  • The public mail hostname, forward/reverse DNS ownership, supported package version and responsibility for ports 25/587/993 are known.
  • A maintenance or canary window, console recovery and current protected backup of configuration, keys, identity mappings and relevant mailbox/queue data exist.
  • Test sender and recipient addresses are owned by the operator; no unsolicited or third-party traffic is generated during verification.
  • Secrets and private keys are delivered outside shell history and have narrowly defined service ownership and rotation plans.

Key concepts

envelope identity
SMTP sender and recipient used for routing, delivery status and SPF; it is distinct from visible message headers.
open relay
An MTA that accepts unauthorized third-party sender-to-recipient forwarding, enabling abuse and reputation damage.
backscatter
A later non-delivery report sent to a forged sender because an invalid recipient was accepted instead of rejected during SMTP.
alignment
DMARC relationship between visible From domain and authenticated SPF or DKIM domain.
Maildir
A mailbox format storing messages as individual files in cur/new/tmp directories with strict ownership.

Before you copy

Values used in this guide

{{domain}}

Fully qualified public or internal hostname served by this configuration.

Example: example.com
{{localTestAddress}}

Operator-reviewed value used by this tutorial for localTestAddress; derive it from the target environment and never from untrusted request data.

Example: postmaster@example.com
{{mailHost}}

Operator-reviewed value used by this tutorial for mailHost; derive it from the target environment and never from untrusted request data.

Example: mail.example.com
{{publicIp}}

Operator-reviewed value used by this tutorial for publicIp; derive it from the target environment and never from untrusted request data.

Example: 192.0.2.20
{{trustedCidr}}

Operator-reviewed value used by this tutorial for trustedCidr; derive it from the target environment and never from untrusted request data.

Example: 192.0.2.0/24

Security and production boundaries

  • Never weaken relay/recipient checks, publish private DKIM/TLS keys, enable plaintext authentication, or expose web/IMAP administration broadly to make a test pass.
  • Mail content, credentials, queues, logs and backups contain personal or confidential data; restrict, encrypt, minimize and retain them under an explicit policy.
  • Use dedicated service identities and root-readable credential maps; verify logs and configuration output are redacted before sharing.

Stop before continuing if

  • Stop if a test permits unauthorized relay, accepts unknown recipients for later bounce, sends credentials without verified TLS, or exposes private keys/mailbox files.
  • Do not continue when hostname/PTR ownership, package/config version, recipient map, route, queue, mailbox ownership or rollback backup is ambiguous.
  • Immediately quarantine the candidate when unrelated mail is rerouted, deleted, multiply delivered, signed by the wrong domain, or inaccessible after reload.
01

instruction

Verify canonical mail DNS

read-only

Confirm hostname, forward address, PTR, MX, and TTLs before Postfix announces or signs the identity.

Why this step matters

Verify canonical mail DNS is a separate checkpoint because it establishes one auditable part of receive mail for owned domains and deliver outbound mail directly with a minimal, auditable postfix configuration. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.

What to understand

Confirm hostname, forward address, PTR, MX, and TTLs before Postfix announces or signs the identity. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.

Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.

Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.

System changes

  • This step may affect the files, packages, identities, services, or runtime policy named in “Verify canonical mail DNS”. The scope must remain limited to the selected application and supported host.

Syntax explained

hostname
Invokes the principal tool or configuration operation for “Verify canonical mail DNS”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}
Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
Command
Fill variables0/3 ready

Values stay on this page and are never sent or saved.

hostname -f; dig +short A {{mailHost}}; dig +short AAAA {{mailHost}}; dig +short -x {{publicIp}}; dig +short MX {{domain}}
Example output / evidence
Forward, reverse, and MX records agree.

Checkpoint: Checkpoint: Verify canonical mail DNS

Continue whenForward, reverse, and MX records agree. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.

Stop whenStop before the next step when hostname reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.

If this step fails

The command for “Verify canonical mail DNS” fails, produces no useful evidence, or the expected service/configuration state is absent.

Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.

Safe checks
  • command -v hostname 2>/dev/null || true
  • systemctl --failed --no-pager 2>/dev/null || true
  • journalctl -p warning -n 50 --no-pager 2>/dev/null || true

ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.

Security notes

  • Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.

Alternatives

  • When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.

Stop conditions

  • Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
02

command

Install Postfix and SMTP test tools

caution

Use the distribution package, select Internet Site only after documenting values, and ensure no other MTA owns port 25.

Why this step matters

Install Postfix and SMTP test tools is a separate checkpoint because it establishes one auditable part of receive mail for owned domains and deliver outbound mail directly with a minimal, auditable postfix configuration. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.

What to understand

Use the distribution package, select Internet Site only after documenting values, and ensure no other MTA owns port 25. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.

Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.

Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.

System changes

  • This step may affect the files, packages, identities, services, or runtime policy named in “Install Postfix and SMTP test tools”. The scope must remain limited to the selected application and supported host.

Syntax explained

apt
Invokes the principal tool or configuration operation for “Install Postfix and SMTP test tools”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
&&
Runs the following operation only when the previous command succeeds, preventing a reload or state transition after a failed validation.
Command
sudo apt update && sudo apt install --yes postfix bsd-mailx swaks ca-certificates dnsutils
Example output / evidence
Postfix installs and systemd owns the intended service.

Checkpoint: Checkpoint: Install Postfix and SMTP test tools

Continue whenPostfix installs and systemd owns the intended service. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.

Stop whenStop before the next step when apt reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.

If this step fails

The command for “Install Postfix and SMTP test tools” fails, produces no useful evidence, or the expected service/configuration state is absent.

Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.

Safe checks
  • command -v apt 2>/dev/null || true
  • systemctl --failed --no-pager 2>/dev/null || true
  • journalctl -p warning -n 50 --no-pager 2>/dev/null || true

ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.

Security notes

  • Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.

Alternatives

  • When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.

Stop conditions

  • Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
03

config

Set hostname, origin, destination, and interfaces

caution

Configure myhostname, myorigin, mydestination, inet_interfaces, and inet_protocols explicitly; avoid accepting undeclared domains.

Why this step matters

Set hostname, origin, destination, and interfaces is a separate checkpoint because it establishes one auditable part of receive mail for owned domains and deliver outbound mail directly with a minimal, auditable postfix configuration. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.

What to understand

Configure myhostname, myorigin, mydestination, inet_interfaces, and inet_protocols explicitly; avoid accepting undeclared domains. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.

Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.

Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.

System changes

  • This step may affect the files, packages, identities, services, or runtime policy named in “Set hostname, origin, destination, and interfaces”. The scope must remain limited to the selected application and supported host.

Syntax explained

postconf
Invokes the principal tool or configuration operation for “Set hostname, origin, destination, and interfaces”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}
Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
/etc/postfix/main.cf
Is the persistent configuration boundary changed by this step. Keep an attributable backup and validate the consumer before reload.
File /etc/postfix/main.cf
Configuration
Fill variables0/2 ready

Values stay on this page and are never sent or saved.

sudo postconf -e 'myhostname={{mailHost}}' 'myorigin=$mydomain' 'mydestination=$myhostname, localhost.$mydomain, localhost, {{domain}}' 'inet_interfaces=all'; postconf -n
Example output / evidence
Canonical identity and local destinations are explicit.

Checkpoint: Checkpoint: Set hostname, origin, destination, and interfaces

Continue whenCanonical identity and local destinations are explicit. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.

Stop whenStop before the next step when postconf reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.

If this step fails

The command for “Set hostname, origin, destination, and interfaces” fails, produces no useful evidence, or the expected service/configuration state is absent.

Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.

Safe checks
  • command -v postconf 2>/dev/null || true
  • systemctl --failed --no-pager 2>/dev/null || true
  • journalctl -p warning -n 50 --no-pager 2>/dev/null || true

ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.

Security notes

  • Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.

Alternatives

  • When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.

Stop conditions

  • Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
04

config

Keep trusted networks narrow

caution

Set mynetworks to loopback and explicit internal submitters only; never trust an entire provider or public subnet.

Why this step matters

Keep trusted networks narrow is a separate checkpoint because it establishes one auditable part of receive mail for owned domains and deliver outbound mail directly with a minimal, auditable postfix configuration. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.

What to understand

Set mynetworks to loopback and explicit internal submitters only; never trust an entire provider or public subnet. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.

Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.

Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.

System changes

  • This step may affect the files, packages, identities, services, or runtime policy named in “Keep trusted networks narrow”. The scope must remain limited to the selected application and supported host.

Syntax explained

postconf
Invokes the principal tool or configuration operation for “Keep trusted networks narrow”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}
Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
configuration file
Is the persistent configuration boundary changed by this step. Keep an attributable backup and validate the consumer before reload.
Configuration
Fill variables0/1 ready

Values stay on this page and are never sent or saved.

sudo postconf -e 'mynetworks=127.0.0.0/8 [::1]/128 {{trustedCidr}}'; postconf mynetworks
Example output / evidence
Only approved sources are trusted.

Checkpoint: Checkpoint: Keep trusted networks narrow

Continue whenOnly approved sources are trusted. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.

Stop whenStop before the next step when postconf reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.

If this step fails

The command for “Keep trusted networks narrow” fails, produces no useful evidence, or the expected service/configuration state is absent.

Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.

Safe checks
  • command -v postconf 2>/dev/null || true
  • systemctl --failed --no-pager 2>/dev/null || true
  • journalctl -p warning -n 50 --no-pager 2>/dev/null || true

ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.

Security notes

  • Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.

Alternatives

  • When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.

Stop conditions

  • Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
05

config

Require authorized destinations or SASL

caution

Use reject_unauth_destination in smtpd_relay_restrictions and keep client/recipient restrictions ordered and testable.

Why this step matters

Require authorized destinations or SASL is a separate checkpoint because it establishes one auditable part of receive mail for owned domains and deliver outbound mail directly with a minimal, auditable postfix configuration. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.

What to understand

Use reject_unauth_destination in smtpd_relay_restrictions and keep client/recipient restrictions ordered and testable. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.

Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.

Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.

System changes

  • This step may affect the files, packages, identities, services, or runtime policy named in “Require authorized destinations or SASL”. The scope must remain limited to the selected application and supported host.

Syntax explained

postconf
Invokes the principal tool or configuration operation for “Require authorized destinations or SASL”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
configuration file
Is the persistent configuration boundary changed by this step. Keep an attributable backup and validate the consumer before reload.
Configuration
sudo postconf -e 'smtpd_relay_restrictions=permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'; postconf smtpd_relay_restrictions
Example output / evidence
Postfix rejects unauthenticated external-to-external relay.

Checkpoint: Checkpoint: Require authorized destinations or SASL

Continue whenPostfix rejects unauthenticated external-to-external relay. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.

Stop whenStop before the next step when postconf reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.

If this step fails

The command for “Require authorized destinations or SASL” fails, produces no useful evidence, or the expected service/configuration state is absent.

Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.

Safe checks
  • command -v postconf 2>/dev/null || true
  • systemctl --failed --no-pager 2>/dev/null || true
  • journalctl -p warning -n 50 --no-pager 2>/dev/null || true

ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.

Security notes

  • Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.

Alternatives

  • When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.

Stop conditions

  • Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
06

config

Route administrative aliases

read-only

Map root, postmaster, abuse, and hostmaster to monitored mailboxes, compile aliases, and query the map.

Why this step matters

Route administrative aliases is a separate checkpoint because it establishes one auditable part of receive mail for owned domains and deliver outbound mail directly with a minimal, auditable postfix configuration. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.

What to understand

Map root, postmaster, abuse, and hostmaster to monitored mailboxes, compile aliases, and query the map. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.

Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.

Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.

System changes

  • This step may affect the files, packages, identities, services, or runtime policy named in “Route administrative aliases”. The scope must remain limited to the selected application and supported host.

Syntax explained

sudoedit
Invokes the principal tool or configuration operation for “Route administrative aliases”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
configuration file
Is the persistent configuration boundary changed by this step. Keep an attributable backup and validate the consumer before reload.
Configuration
sudoedit /etc/aliases; sudo newaliases; postmap -q postmaster hash:/etc/aliases
Example output / evidence
Required administrative addresses resolve.

Checkpoint: Checkpoint: Route administrative aliases

Continue whenRequired administrative addresses resolve. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.

Stop whenStop before the next step when sudoedit reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.

If this step fails

The command for “Route administrative aliases” fails, produces no useful evidence, or the expected service/configuration state is absent.

Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.

Safe checks
  • command -v sudoedit 2>/dev/null || true
  • systemctl --failed --no-pager 2>/dev/null || true
  • journalctl -p warning -n 50 --no-pager 2>/dev/null || true

ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.

Security notes

  • Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.

Alternatives

  • When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.

Stop conditions

  • Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
07

verification

Check configuration, restart, and inspect logs

caution

Run postfix check, inspect non-default configuration, restart, verify listener ownership, and review recent journal/mail log.

Why this step matters

Check configuration, restart, and inspect logs is a separate checkpoint because it establishes one auditable part of receive mail for owned domains and deliver outbound mail directly with a minimal, auditable postfix configuration. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.

What to understand

Run postfix check, inspect non-default configuration, restart, verify listener ownership, and review recent journal/mail log. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.

Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.

Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.

System changes

  • This step may affect the files, packages, identities, services, or runtime policy named in “Check configuration, restart, and inspect logs”. The scope must remain limited to the selected application and supported host.

Syntax explained

postfix
Invokes the principal tool or configuration operation for “Check configuration, restart, and inspect logs”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
|
Passes standard output to the next read-only inspection stage; review each stage separately if the combined result is surprising.
Command
sudo postfix check; postconf -n; sudo systemctl restart postfix; sudo ss -lntp | grep ':25'; sudo journalctl -u postfix -n 100 --no-pager
Example output / evidence
Postfix starts, owns port 25, and reports no configuration error.

Checkpoint: Checkpoint: Check configuration, restart, and inspect logs

Continue whenPostfix starts, owns port 25, and reports no configuration error. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.

Stop whenStop before the next step when postfix reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.

If this step fails

The command for “Check configuration, restart, and inspect logs” fails, produces no useful evidence, or the expected service/configuration state is absent.

Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.

Safe checks
  • command -v postfix 2>/dev/null || true
  • systemctl --failed --no-pager 2>/dev/null || true
  • journalctl -p warning -n 50 --no-pager 2>/dev/null || true

ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.

Security notes

  • Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.

Alternatives

  • When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.

Stop conditions

  • Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
08

verification

Test local acceptance, outbound delivery, and relay denial

read-only

Use tagged swaks messages and preserve SMTP transcript plus queue/log evidence for each expected path.

Why this step matters

Test local acceptance, outbound delivery, and relay denial is a separate checkpoint because it establishes one auditable part of receive mail for owned domains and deliver outbound mail directly with a minimal, auditable postfix configuration. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.

What to understand

Use tagged swaks messages and preserve SMTP transcript plus queue/log evidence for each expected path. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.

Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.

Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.

System changes

  • This step may affect the files, packages, identities, services, or runtime policy named in “Test local acceptance, outbound delivery, and relay denial”. The scope must remain limited to the selected application and supported host.

Syntax explained

swaks
Invokes the principal tool or configuration operation for “Test local acceptance, outbound delivery, and relay denial”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}
Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
Command
Fill variables0/2 ready

Values stay on this page and are never sent or saved.

swaks --server {{mailHost}} --from sender@example.net --to {{localTestAddress}}; swaks --server {{mailHost}} --from sender@example.org --to recipient@example.net
Example output / evidence
Local mail is accepted and unauthenticated relay is rejected with 554 or equivalent.

Checkpoint: Checkpoint: Test local acceptance, outbound delivery, and relay denial

Continue whenLocal mail is accepted and unauthenticated relay is rejected with 554 or equivalent. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.

Stop whenStop before the next step when swaks reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.

If this step fails

The command for “Test local acceptance, outbound delivery, and relay denial” fails, produces no useful evidence, or the expected service/configuration state is absent.

Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.

Safe checks
  • command -v swaks 2>/dev/null || true
  • systemctl --failed --no-pager 2>/dev/null || true
  • journalctl -p warning -n 50 --no-pager 2>/dev/null || true

ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.

Security notes

  • Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.

Alternatives

  • When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.

Stop conditions

  • Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.

Finish line

Verification checklist

Configuration and listenersudo postfix check && sudo ss -lntp | grep ':25'Configuration passes and master owns port 25.
Queue and errorspostqueue -p; sudo journalctl -u postfix -p warning --since '-30 min' --no-pagerQueue state is understood and no unexplained warning remains.

Recovery guidance

Common problems and safe checks

A message remains queued or the remote server returns a temporary 4xx response.

Likely causeDNS/MX resolution, routing, network reachability, TLS negotiation, remote greylisting/rate limits, reputation or recipient policy prevents delivery.

Safe checks
  • exim -bp 2>/dev/null || postqueue -p
  • dig +short MX example.net
  • journalctl -u exim4 -u postfix --since '-30 min' --no-pager

ResolutionInspect one message's recorded diagnostic and route first, fix the evidenced dependency, then retry only that message; do not force an undiagnosed bulk queue.

SMTP accepts a recipient, but the mailbox is absent, unreadable or never visible over IMAP.

Likely causeRecipient maps, LMTP/LDA route, virtual UID/GID, Maildir path, quota, Dovecot namespace or filesystem permissions disagree.

Safe checks
  • doveconf -n
  • doveadm user user@example.com
  • doveadm mailbox list -u user@example.com

ResolutionTrace the exact address through recipient validation, delivery socket and resolved mailbox path; correct the narrow mapping/ownership mismatch before accepting more mail.

Authentication or TLS fails despite apparently correct credentials and certificate files.

Likely causeThe listener uses another configuration, hostname/SAN does not match, chain/key permissions are wrong, authentication is attempted without TLS, or the identity backend maps another username.

Safe checks
  • openssl s_client -connect mail.example.com:587 -starttls smtp -servername mail.example.com </dev/null
  • openssl s_client -connect mail.example.com:993 -servername mail.example.com </dev/null
  • journalctl -u dovecot -u postfix -u exim4 -p warning -n 100 --no-pager

ResolutionVerify the advertised hostname, chain, listener and mapped user independently; never disable certificate verification or enable plaintext authentication to bypass the failure.

After the procedure

Alternatives and next steps

Consider these alternatives

  • Use a reputable managed mail transport or mailbox provider when staffing, deliverability, abuse response, DNS reputation and 24/7 queue operations cannot be sustained.
  • Separate inbound, outbound, submission and mailbox roles across hosts only when TLS identity, routing, backups and observability remain end-to-end testable.

Operate it safely

  • Alert on queue age/depth, delivery deferrals, authentication failures, TLS/certificate expiry, disk/quota pressure, DKIM/DMARC failures and backup restore age.
  • Review relay/recipient maps, dormant users, supported versions, DNS policy and key/certificate rotation at least every 90 days.
  • Practice one-message queue diagnosis and an isolated mailbox/config restore so incident steps are proven before a real outage.

Reference

Frequently asked questions

Why is one successful test email insufficient?

It may bypass the actual external DNS, authentication, recipient, DKIM, queue retry or IMAP path. Test each boundary and preserve protocol/header evidence.

Can TLS be tested by checking that encryption is present?

No. Verify the chain and hostname and ensure authentication is unavailable before STARTTLS; encryption to an unverified endpoint is not server authentication.

Should a stuck queue be forced immediately?

No. Read one message's diagnostic and fix the dependency first. Bulk retries can amplify rate limits, duplicates or reputation damage.

Recovery

Rollback

Restore main.cf, master.cf, aliases, and firewall state while preserving the Postfix queue.

  1. Stop Postfix, restore /etc/postfix and aliases, run postfix check, and start.
  2. Restore firewall rules only after confirming the intended MTA owner of port 25.
  3. Never purge /var/spool/postfix during rollback.

Evidence

Sources and review

Verified 2026-07-25Review due 2026-10-23
Postfix basic configurationofficialPostfix relay and access controlofficialPostfix debugging guidanceofficial