LOCAL(8postfix)

๐Ÿ“ฆ
version 3.8.6 ยท 2 versions
, in debian bookworm, ubuntu noble

๐Ÿ’Œ LOCAL(8postfix) โ€” aka local(8) ๐Ÿ’Œ

okay bestie, sit down, hydrate, because this is the page about local(8) โ€” the Postfix local mail delivery daemon. it's giving workhorse. let's go ๐Ÿซถ


โœจ NAME โœจ

local โ€” Postfix local mail delivery ๐Ÿ’–


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

local [generic Postfix daemon options]

๐ŸŒธ DESCRIPTION ๐ŸŒธ

so the local(8) daemon is the one who handles delivery requests coming in from the Postfix queue manager, and its whole job is getting mail to local recipients. every single delivery request it gets tells it:

  • a queue file ๐Ÿ“
  • a sender address โœ‰๏ธ
  • a domain or host to deliver to ๐ŸŒ
  • and one or more recipients ๐Ÿ‘ฏ

and heads up โ€” this program expects to be run from the master(8) process manager. it's not a solo act, it's a group project (and for once, everyone actually does their part).

what it does with all that: the local(8) daemon updates queue files and marks recipients as finished โœ…, or it tells the queue manager that delivery should be tried again later โฐ. and the delivery status reports? those get sent to the bounce(8), defer(8) or trace(8) daemon, whichever one fits the situation. no cap.


๐Ÿ”ค CASE FOLDING ๐Ÿ”ค

every single delivery decision is made using the bare recipient name โ€” that's the address localpart, bestie โ€” and it's folded to lower case. lowercase supremacy fr fr.

also peep the ADDRESS EXTENSION section below for a few exceptions ๐Ÿ‘€ (there are always exceptions, it's a mail system).

๐Ÿ—‚๏ธ SYSTEM-WIDE AND USER-LEVEL ALIASING ๐Ÿ—‚๏ธ

the system administrator can set up one or more system-wide sendmail-style alias databases. and users? users can have their very own sendmail-style ~/.forward files. iconic behavior.

so mail for name gets delivered to one of these:

  • the alias name ๐Ÿท๏ธ
  • destinations listed inside ~name/.forward ๐Ÿ“ฌ
  • the mailbox owned by the user name ๐Ÿ“ฎ
  • orโ€ฆ it gets sent back as undeliverable ๐Ÿ’€ (the vibe check failed)

the system administrator can specify a comma/space separated list of ~/.forward-like files through the forward_path configuration parameter. upon delivery, the local delivery agent tries each pathname in the list until a file is found. first match wins, periodt.

delivery via ~/.forward files happens with the privileges of the recipient ๐Ÿ‘‘. which means:

  • ~/.forward-like files must be readable by the recipient
  • their parent directory needs to have "execute" permission for the recipient

no permission, no delivery. that's just the rules.


๐Ÿงš forward_path interpolation (this part is spicy) ๐Ÿงš

the forward_path parameter gets interpolated, and it supports all of these lil variables:

  • $user โ€” recipient username
  • $home โ€” recipient home directory
  • $shell โ€” recipient shell
  • $recipient โ€” complete recipient address
  • $extension โ€” recipient address extension
  • $domain โ€” recipient domain
  • $local โ€” entire recipient address localpart
  • $recipient_delimiter

and then there's the conditional glow-up โœจ:

  • the forms ${name?value} and ${name?{value}} (Postfix 3.0 and later) expand conditionally to value when $name is defined
  • the forms ${name:value} and ${name:{value}} (Postfix 3.0 and later) expand conditionally to value when $name is not defined
  • the form ${name?{value1}:{value2}} (Postfix 3.0 and later) expands conditionally to value1 when $name is defined, or value2 otherwise

characters that may have special meaning to the shell or file system get replaced with underscores _. the list of acceptable characters is specified with the forward_expansion_filter configuration parameter. so if you're like "why did my char turn into an underscore" โ€” that's why, bestie ๐Ÿซ 


๐Ÿ“œ what can even go in an alias or .forward file ๐Ÿ“œ

an alias or ~/.forward file may list any combination of:

  • external commands โš™๏ธ
  • destination file names ๐Ÿ“„
  • :include: directives ๐Ÿ“Ž
  • mail addresses โœ‰๏ธ

see aliases(5) for a precise description (go read it, it's thorough). and each line in a user's .forward file has the same syntax as the right-hand part of an alias. yes really.

some specific situations you need to know:

  • when an address is found in its own alias expansion โ†’ delivery is made to the user instead ๐Ÿ”
  • when a user is listed in the user's own ~/.forward file โ†’ delivery is made to the user's mailbox instead ๐Ÿ“ฅ
  • an empty ~/.forward file means do not forward mail ๐Ÿšซ (empty file, loud statement)

and to stop the mail system from eating up unreasonable amounts of memory ๐Ÿ˜ญ, input records read from :include: or from ~/.forward files get broken up into chunks of length line_length_limit.

while expanding aliases, ~/.forward files, and so on, the program tries to avoid duplicate deliveries ๐Ÿง . the duplicate_filter_limit configuration parameter limits the number of remembered recipients. it has a memory budget and it's sticking to it.


๐Ÿ“ค MAIL FORWARDING ๐Ÿ“ค

for the sake of reliability, forwarded mail is re-submitted as a new message โœจ, so that each recipient has a separate on-file delivery status record. every recipient gets their own receipt, no sharing.

and in order to stop mail forwarding loops early ๐Ÿ›‘, the software adds an optional Delivered-To: header with the final envelope recipient address.

๐Ÿšจ if mail arrives for a recipient that is already listed in a Delivered-To: header, the message is bounced. loop detected, delivery denied, sorry bestie.

๐Ÿ“ฌ MAILBOX DELIVERY ๐Ÿ“ฌ

the default spot ๐Ÿ 

the default per-user mailbox is a file in the UNIX mail spool directory: /var/mail/user or /var/spool/mail/user. the location can be specified with the mail_spool_directory configuration parameter.

๐Ÿ’… specify a name ending in / for qmail-compatible maildir delivery.

the home directory option ๐Ÿก

alternatively, the per-user mailbox can be a file in the user's home directory, with a name specified via the home_mailbox configuration parameter. specify a relative path name.

๐Ÿ’… and again โ€” specify a name ending in / for qmail-compatible maildir delivery. same trick, different house.

delegating to an external command โš™๏ธ

mailbox delivery can be delegated to an external command specified with the mailbox_command_maps and mailbox_command configuration parameters.

the command executes with the privileges of the recipient user, with two exceptions you need to know:

  • secondary groups are not enabled
  • in case of delivery as root, the command executes with the privileges of default_privs

delegating to alternative transports ๐Ÿšš

mailbox delivery can also be delegated to alternative message transports specified in the master.cf file. here's the split:

  • the mailbox_transport_maps and mailbox_transport configuration parameters specify an optional message transport that is to be used for all local recipients, regardless of whether they are found in the UNIX passwd database
  • the fallback_transport_maps and fallback_transport parameters specify an optional message transport for recipients that are not found in the aliases(5) or UNIX passwd database

๐Ÿ—ƒ๏ธ UNIX-style mailbox delivery: what actually gets written ๐Ÿ—ƒ๏ธ

in the case of UNIX-style mailbox delivery, the local(8) daemon does a whole lil ritual:

  • prepends a "From sender time_stamp" envelope header to each message
  • prepends an X-Original-To: header with the recipient address as given to Postfix
  • prepends an optional Delivered-To: header with the final envelope recipient address
  • prepends a Return-Path: header with the envelope sender address
  • prepends a > character to lines beginning with "From "
  • and appends an empty line

the mailbox is locked for exclusive access while delivery is in progress ๐Ÿ”’. and in case of problems, an attempt is made to truncate the mailbox to its original length. damage control, we love to see it.

๐Ÿ—‚๏ธ maildir delivery: what actually gets written ๐Ÿ—‚๏ธ

in the case of maildir delivery, the local daemon keeps it lighter:

  • prepends an optional Delivered-To: header with the final envelope recipient address
  • prepends an X-Original-To: header with the recipient address as given to Postfix
  • and prepends a Return-Path: header with the envelope sender address

okay bestie we're back and we're going even deeper into delivery town ๐Ÿ’… strap in.


๐Ÿ“ฆ EXTERNAL COMMAND DELIVERY ๐Ÿ“ฆ

So you want Postfix to run a command instead of dropping mail in a box? Iconic. But there are rules, bestie.

The allow_mail_to_commands configuration parameter restricts delivery to external commands. The default setting (alias, forward) forbids command destinations in :include: files.

Optionally, the process working directory is changed to the path specified with command_execution_directory (Postfix 2.2 and later). Failure to change directory causes mail to be deferred. ๐Ÿ˜ญ

The command_execution_directory parameter value is subject to interpolation of:

  • $user โ€” recipient username
  • $home โ€” recipient home directory
  • $shell โ€” recipient shell
  • $recipient โ€” complete recipient address
  • $extension โ€” recipient address extension
  • $domain โ€” recipient domain
  • $local โ€” entire recipient address localpart
  • $recipient_delimiter

The forms ${name?value} and ${name?{value}} (Postfix 3.0 and later) expand conditionally to value when $name is defined, and the forms ${name:value} and ${name:{value}} (Postfix 3.0 and later) expand conditionally to value when $name is not defined. The form ${name?{value1}:{value2}} (Postfix 3.0 and later) expands conditionally to value1 when $name is defined, or value2 otherwise. Characters that may have special meaning to the shell or file system are replaced with underscores. The list of acceptable characters is specified with the execution_directory_expansion_filter configuration parameter.

The command is executed directly where possible. Assistance by the shell (/bin/sh on UNIX systems) is used only when the command contains shell magic characters, or when the command invokes a shell built-in command.

A limited amount of command output (standard output and standard error) is captured for inclusion with non-delivery status reports. A command is forcibly terminated if it does not complete within command_time_limit seconds. Command exit status codes are expected to follow the conventions defined in <sysexits.h>. Exit status 0 means normal successful completion.

Postfix version 2.3 and later support RFC 3463-style enhanced status codes. If a command terminates with a non-zero exit status, and the command output begins with an enhanced status code, this status code takes precedence over the non-zero exit status.

A limited amount of message context is exported via environment variables. Characters that may have special meaning to the shell are replaced with underscores. The list of acceptable characters is specified with the command_expansion_filter configuration parameter.


๐ŸŒˆ the env var lineup ๐ŸŒˆ

  • SHELL โ€” The recipient user's login shell.
  • HOME โ€” The recipient user's home directory.
  • USER โ€” The bare recipient name.
  • EXTENSION โ€” The optional recipient address extension.
  • DOMAIN โ€” The recipient address domain part.
  • LOGNAME โ€” The bare recipient name.
  • LOCAL โ€” The entire recipient address localpart (text to the left of the rightmost @ character).
  • ORIGINAL_RECIPIENT โ€” The entire recipient address, before any address rewriting or aliasing (Postfix 2.5 and later).
  • RECIPIENT โ€” The entire recipient address.
  • SENDER โ€” The entire sender address.

Additional remote client information is made available via the following environment variables:

  • CLIENT_ADDRESS โ€” Remote client network address. Available as of Postfix 2.2.
  • CLIENT_HELO โ€” Remote client EHLO command parameter. Available as of Postfix 2.2.
  • CLIENT_HOSTNAME โ€” Remote client hostname. Available as of Postfix 2.2.
  • CLIENT_PROTOCOL โ€” Remote client protocol. Available as of Postfix 2.2.
  • SASL_METHOD โ€” SASL authentication method specified in the remote client AUTH command. Available as of Postfix 2.2.
  • SASL_SENDER โ€” SASL sender address specified in the remote client MAIL FROM command. Available as of Postfix 2.2.
  • SASL_USERNAME โ€” SASL username specified in the remote client AUTH command. Available as of Postfix 2.2.

The PATH environment variable is always reset to a system-dependent default path, and environment variables whose names are blessed by the export_environment configuration parameter are exported unchanged.

The current working directory is the mail queue directory.

The local(8) daemon prepends a "From sender time_stamp" envelope header to each message, prepends an X-Original-To: header with the recipient address as given to Postfix, prepends an optional Delivered-To: header with the final recipient envelope address, prepends a Return-Path: header with the sender envelope address, and appends no empty line.


๐Ÿ—‚๏ธ EXTERNAL FILE DELIVERY ๐Ÿ—‚๏ธ

The delivery format depends on the destination filename syntax. The default is to use UNIX-style mailbox format. Specify a name ending in / for qmail-compatible maildir delivery.

The allow_mail_to_files configuration parameter restricts delivery to external files. The default setting (alias, forward) forbids file destinations in :include: files.

In the case of UNIX-style mailbox delivery, the local(8) daemon prepends a "From sender time_stamp" envelope header to each message, prepends an X-Original-To: header with the recipient address as given to Postfix, prepends an optional Delivered-To: header with the final recipient envelope address, prepends a > character to lines beginning with "From ", and appends an empty line. The envelope sender address is available in the Return-Path: header. When the destination is a regular file, it is locked for exclusive access while delivery is in progress. In case of problems, an attempt is made to truncate a regular file to its original length.

In the case of maildir delivery, the local daemon prepends an optional Delivered-To: header with the final envelope recipient address, and prepends an X-Original-To: header with the recipient address as given to Postfix. The envelope sender address is available in the Return-Path: header.


โž• ADDRESS EXTENSION โž•

The optional recipient_delimiter configuration parameter specifies how to separate address extensions from local recipient names.

For example, with "recipient_delimiter = +", mail for name+foo is delivered to the alias name+foo or to the alias name, to the destinations listed in ~name/.forward+foo or in ~name/.forward, to the mailbox owned by the user name, or it is sent back as undeliverable.


๐Ÿ” DELIVERY RIGHTS ๐Ÿ”

Deliveries to external files and external commands are made with the rights of the receiving user on whose behalf the delivery is made. In the absence of a user context, the local(8) daemon uses the owner rights of the :include: file or alias database. When those files are owned by the superuser, delivery is made with the rights specified with the default_privs configuration parameter.


๐Ÿ“œ STANDARDS ๐Ÿ“œ


๐Ÿฉบ DIAGNOSTICS ๐Ÿฉบ

Problems and transactions are logged to syslogd(8) or postlogd(8). Corrupted message files are marked so that the queue manager can move them to the corrupt queue afterwards.

Depending on the setting of the notify_classes parameter, the postmaster is notified of bounces and of other trouble.


๐Ÿ›ก๏ธ SECURITY ๐Ÿ›ก๏ธ

The local(8) delivery agent needs a dual personality: 1) to access the private Postfix queue and IPC mechanisms, 2) to impersonate the recipient and deliver to recipient-specified files or commands. It is therefore security sensitive. ๐Ÿ˜ณ

The local(8) delivery agent disallows regular expression substitution of $1 etc. in alias_maps, because that would open a security hole.

The local(8) delivery agent will silently ignore requests to use the proxymap(8) server within alias_maps. Instead it will open the table directly. Before Postfix version 2.2, the local(8) delivery agent will terminate with a fatal error.


๐Ÿ’€ BUGS ๐Ÿ’€

For security reasons, the message delivery status of external commands or of external files is never checkpointed to file. As a result, the program may occasionally deliver more than once to a command or external file. Better safe than sorry.

Mutually-recursive aliases or ~/.forward files are not detected early. The resulting mail forwarding loop is broken by the use of the Delivered-To: message header.


โš™๏ธ CONFIGURATION PARAMETERS โš™๏ธ

Changes to main.cf are picked up automatically, as local(8) processes run for only a limited amount of time. Use the command "postfix reload" to speed up a change.

The text below provides only a parameter summary. See postconf(5) for more details including examples.


๐Ÿงธ COMPATIBILITY CONTROLS ๐Ÿงธ

  • biff (yes) โ€” Whether or not to use the local biff service.
  • expand_owner_alias (no) โ€” When delivering to an alias "aliasname" that has an "owner-aliasname" companion alias, set the envelope sender address to the expansion of the "owner-aliasname" alias.
  • owner_request_special (yes) โ€” Enable special treatment for owner-listname entries in the aliases(5) file, and don't split owner-listname and listname-request address localparts when the recipient_delimiter is set to "-".
  • sun_mailtool_compatibility (no) โ€” Obsolete SUN mailtool compatibility feature.

Available in Postfix version 2.3 and later:

  • frozen_delivered_to (yes) โ€” Update the local(8) delivery agent's idea of the Delivered-To: address (see prepend_delivered_header) only once, at the start of a delivery attempt; do not update the Delivered-To: address while expanding aliases or .forward files.

Available in Postfix version 2.5.3 and later:

  • strict_mailbox_ownership (yes) โ€” Defer delivery when a mailbox file is not owned by its recipient.
  • reset_owner_alias (no) โ€” Reset the local(8) delivery agent's idea of the owner-alias attribute, when delivering mail to a child alias that does not have its own owner alias.

Available in Postfix version 3.0 and later:

  • local_delivery_status_filter ($default_delivery_status_filter) โ€” Optional filter for the local(8) delivery agent to change the status code or explanatory text of successful or unsuccessful deliveries.

Available in Postfix version 2.2 and later:

  • command_execution_directory (default: empty) โ€” the working directory that the local(8) delivery agent uses when it's delivering to external commands. โœจ

๐Ÿ”’ MAILBOX LOCKING CONTROLS ๐Ÿ”’

locking discourse incoming, bestie. hold my iced coffee. ๐ŸงŠ

  • deliver_lock_attempts (default: 20) โ€” how many times it'll try to grab an exclusive lock on a mailbox file or a bounce(8) logfile before giving up. yes, it tries twenty times, she's persistent ๐Ÿ’…
  • deliver_lock_delay (default: 1s) โ€” the lil pause between those attempts to grab an exclusive lock on a mailbox file or bounce(8) logfile.
  • stale_lock_time (default: 500s) โ€” how long a stale exclusive mailbox lockfile has to sit there being crusty before it gets removed. expired, gatekept, deleted. ๐Ÿ’€
  • mailbox_delivery_lock (default: check postconf -d, she'll tell you) โ€” how to lock a UNIX-style local(8) mailbox before even attempting delivery.

๐Ÿ“ RESOURCE AND RATE CONTROLS ๐Ÿ“

the "chill, don't spiral" section fr fr.

  • command_time_limit (default: 1000s) โ€” the time limit for delivering to external commands. clock's ticking bestie โฐ
  • duplicate_filter_limit (default: 1000) โ€” the max number of addresses the address duplicate filter remembers during aliases(5) or virtual(5) alias expansion, or for showq(8) queue displays. she's got a memory cap, iconic.
  • mailbox_size_limit (default: 51200000) โ€” the biggest size allowed for any local(8) individual mailbox or maildir file. or zero, which means no limit at all. zero = unhinged, no cap, live your truth. ๐Ÿ”ฅ

Implemented in the qmgr(8) daemon:

  • local_destination_concurrency_limit (default: 2) โ€” the max number of parallel deliveries via the local mail delivery transport to the same recipient (that's when "local_destination_recipient_limit = 1"), or the max number of parallel deliveries to the same local domain (that's when "local_destination_recipient_limit > 1"). pick your fighter. ๐ŸฅŠ
  • local_destination_recipient_limit (default: 1) โ€” the max number of recipients per message delivery via the local mail delivery transport.

๐Ÿ›ก๏ธ SECURITY CONTROLS ๐Ÿ›ก๏ธ

okay bestie, this is the part where we lock the doors. no cap. ๐Ÿ”

  • allow_mail_to_commands (default: alias, forward) โ€” restricts local(8) mail delivery to external commands. keep it tight.
  • allow_mail_to_files (default: alias, forward) โ€” restricts local(8) mail delivery to external files.
  • command_expansion_filter (default: whatever postconf -d says) โ€” restricts which characters the local(8) delivery agent will allow inside $name expansions of $mailbox_command and $command_execution_directory. ๐Ÿšซ
  • default_privs (default: nobody) โ€” the default rights the local(8) delivery agent uses when delivering to an external file or command.
  • forward_expansion_filter (default: check postconf -d) โ€” restricts which characters the local(8) delivery agent will allow inside $name expansions of $forward_path.

Available in Postfix version 2.2 and later:

  • execution_directory_expansion_filter (default: check postconf -d) โ€” restricts which characters the local(8) delivery agent will allow inside $name expansions of $command_execution_directory.

Available in Postfix version 2.5.3 and later:

  • strict_mailbox_ownership (default: yes) โ€” when a mailbox file is not owned by its recipient, delivery gets deferred. yes bestie, she WILL hold your mail hostage over ownership. protect yourself. ๐Ÿซถ

๐ŸŒˆ MISCELLANEOUS CONTROLS ๐ŸŒˆ

the grab-bag section, the junk drawer, the "and also these" ๐Ÿ’–

  • config_directory (default: check postconf -d) โ€” the default location of the Postfix main.cf and master.cf configuration files.
  • daemon_timeout (default: 18000s) โ€” how long a Postfix daemon process gets to handle a request before a built-in watchdog timer terminates it. she has a curfew. โณ
  • delay_logging_resolution_limit (default: 2) โ€” the max number of digits after the decimal point when logging sub-second delay values.
  • export_environment (default: check postconf -d) โ€” the list of environment variables that a Postfix process exports to non-Postfix processes.
  • ipc_timeout (default: 3600s) โ€” the time limit for sending or receiving info over an internal communication channel.
  • local_command_shell (default: empty) โ€” optional shell program for local(8) delivery to non-Postfix commands.
  • max_idle (default: 100s) โ€” the max amount of time an idle Postfix daemon process waits for an incoming connection before it voluntarily terminates itself. she leaves the party when it's not fun anymore, respect. โœจ
  • max_use (default: 100) โ€” the max number of incoming connections a Postfix daemon process will service before it voluntarily terminates itself.
  • prepend_delivered_header (default: command, file, forward) โ€” the message delivery contexts where the Postfix local(8) delivery agent prepends a Delivered-To: message header containing the address the mail was delivered to.
  • process_id (read-only) โ€” the process ID of a Postfix command or daemon process.
  • process_name (read-only) โ€” the process name of a Postfix command or daemon process.
  • propagate_unmatched_extensions (default: canonical, virtual) โ€” which address lookup tables copy an address extension from the lookup key over to the lookup result.
  • queue_directory (default: check postconf -d) โ€” the location of the Postfix top-level queue directory.
  • recipient_delimiter (default: empty) โ€” the set of characters that can separate an email address localpart, user name, or a .forward file name from its extension.
  • require_home_directory (default: no) โ€” require that a local(8) recipient's home directory actually exists before mail delivery is attempted.
  • syslog_facility (default: mail) โ€” the syslog facility of Postfix logging.
  • syslog_name (default: check postconf -d) โ€” a prefix that gets prepended to the process name in syslog records, so that, for example, "smtpd" becomes "prefix/smtpd". cute lil name tag ๐Ÿท๏ธ

Available in Postfix version 3.3 and later:

  • enable_original_recipient (default: yes) โ€” enables support for the original recipient address after an address has been rewritten to a different address (for example with aliasing or with canonical mapping).
  • service_name (read-only) โ€” the master.cf service name of a Postfix daemon process.

Available in Postfix 3.5 and later:

  • info_log_address_format (default: external) โ€” the email address form that gets used in non-debug logging (info, warning, etc.).

๐Ÿ“ FILES ๐Ÿ“

bestie these are just examples, the deets differ between systems. don't come for me. ๐Ÿ™ˆ

$HOME/.forward, per-user aliasing
/etc/aliases, system-wide alias database
/var/spool/mail, system mailboxes

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

the whole friend group, go follow them:


๐Ÿ“œ LICENSE ๐Ÿ“œ

The Secure Mailer license must be distributed with this software. that's it, that's the rule, respect the license bestie. ๐Ÿซก


๐Ÿ•ฐ๏ธ HISTORY ๐Ÿ•ฐ๏ธ

the lore drop:

  • The Delivered-To: message header appears in the qmail system by Daniel Bernstein.
  • The maildir structure appears in the qmail system by Daniel Bernstein.

๐Ÿ‘‘ AUTHOR(S) ๐Ÿ‘‘

the icon, the legend, the moment:

Wietse Venema
IBM T.J. Watson Research
P.O. Box 704
Yorktown Heights, NY 10598, USA
Wietse Venema
Google, Inc.
111 8th Avenue
New York, NY 10011, USA

and that's a wrap on LOCAL(8postfix) bestie ๐Ÿ’– the source/version tag at the bottom of the page reads LOCAL(8postfix) โ€” go check your local postconf -d output for the date-ish vibes, mwah, slay, you're officially a local delivery expert now ๐ŸŒธ๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from