Dwarf Mail Server 1.1.3

SMTP Server Architecture



This document explains the SMTP server internal architecture and covers also some related configuration options.


SMTP server consist of two independent parts. The first one receives mail messages from the network clients and puts them into the mail queue. The second one picks up messages from the queue, process them and delivers to final recipients. Since both parts are in fact multi-threaded servers (SMTPServer and QueueManager), the message handling is fast, robust and well configurable. In addition, the physical representation of the mail queue is abstracted via the MailQueue interface, which adds another level of flexibility to the engine.

Mail processing phases

The mail processing loop consists of the following phases:

  1. mail message is received via SMTP connection by SMTPServer and immediatelly put into the mail queue. The message content is not parsed at all at this point - it is taken as a pure byte stream, therefore this step is very fast and the message is put to the queue without any unnecessary delays. If the message is submitted by a local application code, it is put to the queue directly, bypassing the network connection and SMTP protocol overhead. Once in the queue, message waits there for a further processing.

  2. enqueued message is picked up by QueueManager in the time when queue is scanned for any unfinished messages. If the message is newly arrived, it is passed first to the mail agents for preprocessing with the complete set of its recipients (see the Preprocessing interface). After message is preprocessed it is scheduled for delivery to all recipients which have not been finished by mail agents.

  3. if an already preprocessed message is picked up from the queue, the server attempts to deliver it to a subset of its unfinished recipients. In the case of a local recipient it is delivered immediatelly to a local mailbox. If the recipient is not local, the server tries to deliver the message to the remote SMTP host, which may be either a final destination, or an intermediate SMTP relay.

  4. if the delivery process succeeds or permanently fails for the particular subset of recipients, they are marked as finished and the message is passed to the mail agents for postprocessing with the set of finished recipients (see the Postprocessing interface). If the remote delivery fails for a temporary reason, the recipients are marked as deferred and the message is scheduled again for delivery. Such message will be picked up next time the queue is scanned for an unfinished mesages*.

  5. mail queue is scanned in regular intervals for finished messages and these messages are removed permanently from the queue. (A message is finished if all its recipients have been finished.)

(*In fact, the interval of attempting to deliver a deferred message is not constant - it grows in time, up to the delivery timeout limit, when the recipients are finally considered unreachable and marked as failed.)

Mail queue

Mail queue is organized in so-called nodes and message processing is always scheduled for the particular node and time. A node may represent either the preprocessing phase, or the delivery phase. Preprocessing node is identified by the "#process" string and is used just once, when the message arrives to the mail queue and is going to be preprocessed by mail agents. Delivery node represents the domain part of each unfinished recipient's address. If a message is sent to "joe@public.com", for example, it will be scheduled for node identified by the "public.com" string and some time in the near future.
In addition to the mentioned preprocessing and delivery nodes there are some useful macros available, too: "#all" represents both preprocessing phase and delivery to all domains, "#local" represents delivery only to local domains and "#remote" only to remote ones.

The queue processing may be affected in the following ways:

Performance tuning

SMTP server performance may be tuned in several ways.

Return to the main page.

Copyright (c) 2004-2005, Gnome Ltd. All rights reserved.