Postfix Architecture Overview


Introduction

This document presents an overview of the Postfix architecture, and provides pointers to descriptions of every Postfix command or server program. The text gives the general context in which each command or server program is used, and provides pointers to documents with specific usage examples and background information.

Topics covered by this document:

  • How Postfix receives mail
  • How Postfix delivers mail

How Postfix receives mail

When a message enters the Postfix mail system, the first stop on the inside is the incoming queue. The figure below shows the main processes that are involved with new mail. Names followed by a number are Postfix commands or server programs, while unnumbered names inside shaded areas represent Postfix queues.

trivial-
rewrite(8)
Network -> smtpd(8)
^
|
|
v
\
Network -> qmqpd(8) -> cleanup(8) -> incoming
/
pickup(8) <- maildrop
^
|
Local -> sendmail(1) -> postdrop(1)
  • Network mail enters Postfix via the smtpd(8) or qmqpd(8) servers. These servers remove the SMTP or QMQP protocol encapsulation, enforce some sanity checks to protect Postfix, and give the sender, recipients and message content to the cleanup(8) server. The smtpd(8) server can be configured to block unwanted mail, as described in the SMTPD_ACCESS_README document.
  • Local submissions are received with the Postfix sendmail(1) compatibility command, and are queued in the maildrop queue by the privileged postdrop(1) command. This arrangement even works while the Postfix mail system is not running. The local pickup(8) server picks up local submissions, enforces some sanity checks to protect Postfix, and gives the sender, recipients and message content to the cleanup(8) server.
  • Mail from internal sources is given directly to the cleanup(8) server. These sources are not shown in the figure, and include: mail that is forwarded by the local(8) delivery agent (see next section), messages that are returned to the sender by the bounce(8) server (see second-next section), and postmaster notifications about problems with Postfix.
  • The cleanup(8) server implements the final processing stage before mail is queued. It adds missing From: and other message headers, and transforms addresses as described in the ADDRESS_REWRITING_README document. Optionally, the cleanup(8) server can be configured to do light-weight content inspection with regular expressions as described in the BUILTIN_FILTER_README document. The cleanup(8) server places the result as a single file into the incoming queue, and notifies the queue manager (see next section) of the arrival of new mail.
  • The trivial-rewrite(8) server rewrites addresses to the standard “user@fully.qualified.domain” form, as described in the ADDRESS_REWRITING_README document. Postfix currently does not implement a rewriting language, but a lot can be done via table lookups and, if need be, regular expressions.

How Postfix delivers mail

Once a message has reached the incoming queue the next step is to deliver it. The figure shows the main components of the Postfix mail delivery apparatus. Names followed by a number are Postfix commands or server programs, while unnumbered names inside shaded areas represent Postfix queues.

trivial-
rewrite(8)
smtp(8) -> Network
/
^
|
|
v
- lmtp(8) -> Network
/
incoming -> active -> qmgr(8) --- local(8) -> File, command
^
|
|
v
\
- virtual(8) -> File
deferred \
pipe(8) -> Command
  • The queue manager (the qmgr(8) server process in the figure) is the heart of Postfix mail delivery. It contacts the
    smtp(8), lmtp(8), local(8), virtual(8), pipe(8), discard(8) or error(8) delivery agents, and sends a delivery request for one or more recipient addresses. The discard(8) and error(8) delivery agents are special: they discard or bounce all mail, and are not shown in the figure above.The queue manager maintains a small active queue with the messages that it has opened for delivery. The active queue acts as a limited window on potentially large incoming or deferred queues. The limited active queue prevents the queue manager from running out of memory under heavy load. The queue manager maintains a separate deferred queue for mail that cannot be delivered, so that a large mail backlog will not slow down normal queue accesses. The queue manager’s strategy for delayed mail delivery attempts is described in the QSHAPE_README and TUNING_README documents.
  • The trivial-rewrite(8) server resolves each recipient address according to its local or remote address class, as defined in the ADDRESS_CLASS_README document. Additional routing information can be specified with the optional transport(5) table. The trivial-rewrite(8) server optionally queries the relocated(5) table for recipients whose address has changed; mail for such recipients is returned to the sender with an explanation.
  • The smtp(8) client looks up a list of mail exchangers for the destination host, sorts the list by preference, and tries each server in turn until it finds a server that responds. It then encapsulates the sender, recipient and message content as required by the SMTP protocol; this includes conversion of 8-bit MIME to 7-bit encoding.
  • The lmtp(8) client speaks a protocol similar to SMTP that is optimized for delivery to mailbox servers such as Cyrus. The advantage of this setup is that one Postfix machine can feed multiple mailbox servers over LMTP. The opposite is true as well: one mailbox server can be fed over LMTP by multiple Postfix machines.
  • The local(8) delivery agent understands UNIX-style mailboxes, qmail-compatible maildir files, Sendmail-style system-wide aliases(5) databases, and Sendmail-style per-user .forward files. Multiple local delivery agents can be run in parallel, but parallel delivery to the same user is usually limited. The local(8) delivery agent has hooks for alternative forms of local delivery: you can configure it to deliver to mailbox files in user home directories, you can configure it to delegate mailbox delivery to an external command such as procmail, or you can delegate
    delivery to a different Postfix delivery agent.
  • The virtual(8) delivery agent is a bare-bones delivery agent that delivers to UNIX-style mailbox or qmail-style maildir files only. This delivery agent can deliver mail for multiple domains, which makes it especially suitable for hosting lots of small domains on a single machine. This is described in the VIRTUAL_README document.
  • The pipe(8) mailer is the outbound interface to other mail processing systems (the Postfix sendmail(1) command being the inbound interface). The interface is UNIX compatible: it provides information on the command line and on the standard input stream, and expects a process exit status code as defined in <sysexits.h>. Examples of delivery via the pipe(8) mailer are in the MAILDROP_README and UUCP_README documents.

[cfields]adsright[/cfields]