LOCAL(8postfix)
๐ 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$nameis defined - the forms
${name:value}and${name:{value}}(Postfix 3.0 and later) expand conditionally to value when$nameis not defined - the form
${name?{value1}:{value2}}(Postfix 3.0 and later) expands conditionally to value1 when$nameis 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
~/.forwardfile โ delivery is made to the user's mailbox instead ๐ฅ - an empty
~/.forwardfile 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_mapsandmailbox_transportconfiguration parameters specify an optional message transport that is to be used for all local recipients, regardless of whether they are found in the UNIXpasswddatabase - the
fallback_transport_mapsandfallback_transportparameters specify an optional message transport for recipients that are not found in thealiases(5)or UNIXpasswddatabase
๐๏ธ 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 forowner-listnameentries in thealiases(5)file, and don't splitowner-listnameandlistname-requestaddress localparts when therecipient_delimiteris set to"-".sun_mailtool_compatibility(no) โ Obsolete SUN mailtool compatibility feature.
Available in Postfix version 2.3 and later:
frozen_delivered_to(yes) โ Update thelocal(8)delivery agent's idea of theDelivered-To:address (seeprepend_delivered_header) only once, at the start of a delivery attempt; do not update theDelivered-To:address while expanding aliases or.forwardfiles.
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 thelocal(8)delivery agent's idea of theowner-aliasattribute, 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 thelocal(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 thelocal(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 abounce(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 orbounce(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: checkpostconf -d, she'll tell you) โ how to lock a UNIX-stylelocal(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 duringaliases(5)orvirtual(5)alias expansion, or forshowq(8)queue displays. she's got a memory cap, iconic.mailbox_size_limit(default:51200000) โ the biggest size allowed for anylocal(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) โ restrictslocal(8)mail delivery to external commands. keep it tight.allow_mail_to_files(default:alias, forward) โ restrictslocal(8)mail delivery to external files.command_expansion_filter(default: whateverpostconf -dsays) โ restricts which characters thelocal(8)delivery agent will allow inside$nameexpansions of$mailbox_commandand$command_execution_directory. ๐ซdefault_privs(default:nobody) โ the default rights thelocal(8)delivery agent uses when delivering to an external file or command.forward_expansion_filter(default: checkpostconf -d) โ restricts which characters thelocal(8)delivery agent will allow inside$nameexpansions of$forward_path.
Available in Postfix version 2.2 and later:
execution_directory_expansion_filter(default: checkpostconf -d) โ restricts which characters thelocal(8)delivery agent will allow inside$nameexpansions 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: checkpostconf -d) โ the default location of the Postfixmain.cfandmaster.cfconfiguration 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: checkpostconf -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 forlocal(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 Postfixlocal(8)delivery agent prepends aDelivered-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: checkpostconf -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.forwardfile name from its extension.require_home_directory(default:no) โ require that alocal(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: checkpostconf -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) โ themaster.cfservice 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:
qmgr(8), queue managerbounce(8), delivery status reportsnewaliases(1), create/update alias databasepostalias(1), create/update alias databasealiases(5), format of alias databasepostconf(5), configuration parametersmaster(5), generic daemon optionspostlogd(8), Postfix loggingsyslogd(8), system logging
๐ 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
- debian bookworm: postfix 3.7.11-0+deb12u1
- ubuntu noble: postfix 3.8.6-1build2
- ubuntu noble: postfix 3.8.6-1ubuntu0.1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms