Mail Delivery
From This or Other Hosts
The foreign mail server will start an SMTP session with your server to send the mail. It opens a connection to port 25 (usually) and waits to converse in SMTP-speak.
TCPSERVER listens to the SMTP port and once a connection is made, it runs some basic checks. In its control files, you can ban servers from connecting to you. It can also perform reverse DNS lookups and check for known SPAM originators. If everthing is fine, it spawns a new process and passes the connection to QMAIL-SMTPD.
QMAIL-SMTPD talks with the foriegn mail server and accepts the message. It spawns QMAIL-QUEUE to insert the message into the queue. After the connection is closed, these processes end.
Each message is associated with an “envelope” containing the return path for the mail (usually Sender address) and the recipient’s adresses. The email data contains the mail headers and message body. Note that the headers are only data to the mail system and may be easily forged; you should only trust the envelope information. Even then, that may be unwise as that can be forged as well. Face it, email is not secure. Only by performing confirmations can we be reasonable sure it can from the indended email address.
QMAIL-QUEUE communicates with its parent process (which intends to place the message in the queue) via a set of 3 pipes (for message data, envelope sender, and recipient lists). Its architecture is odd, but serviceable. Once a message is placed in the queue, a trigger is pulled. This trigger is a named pipe ($qmail_home/queue/lock/trigger) that wakes up QMAIL-SEND to process it. See the discussion later on “The Qmail Queue” for more information. Depending on the recipient address, the mail will be sent to the “local” (incoming) or “remote” (outgoing) queue.
QMAIL-SEND is the “mother program” of Qmail. It waits for new mail and reschedules deliveries of old mail (that had be deferred until later). It uses a series of pipes to communicate with QMAIL-LSPAWN and QMAIL-RSPAWN to tell them which message to deliver and listens for results from these processes.
QMAIL-LSPAWN is spawned from QMAIL-SEND when Qmail is started. It waits until and order to deliver a message is heard on it pipe from QMAIL-SEND. This program takes the receipient addresses for the mail message and spawns a QMAIL-LOCAL process (as the owner of that mailbox) for each local address to receive the message. When it is done, it sends back the news to QMAIL-SEND. If the user was not found, it delivers it to Qmail’s “alias” user at the alias directory ($qmail_home/alias).
LSPAWN can also use a hashed table to hold user id’s. The QMAIL-USER and QMAIL-NEWU commands takes records in a text file and converts then to Qmail’s .CDB binary file format for fast lookup. This can be used whenever a delivery occurs to non-system-users.
QMAIL-GETPW is a spawn command that LSPAWN used to lookup the recipient user account information in the /etc/passwd file. It sends the result on STDOUT, which LSPAWN gleefully slurps up and cuts up.
QMAIL-LOCAL is the program that finally may make the delivery. It expects to be loaded by QMAIL-LSPAWN as the user of the account receiving the mail, and pointed to the “home directory” or other directory associated with that user in the system. It is pass the “delivery address” which can be complex delivery address or command.
If the user has set up their Qmail configuation files right, it can be a very powerful incoming mail processor. (This is where the email application part comes in.) If the config files are not found, it will deliver it to the mailbox file (or directory) for that user. However, if it is sent to the alias directory, and it can not otherwise delover the message, it is bounced to the original user (by QMAIL-SEND) and no delivery takes place.
The .QMAIL (dot-qmail) files are like Qmail mini-scripts that list actions that need to take place for the message. It can be a command, forward address, or a mailbox name. Each line is executed until the end of the script is reached, or until a program exits with code 99 (stop processing, delivery success) or 100 (stop processing, schedule for retry later). Any action that take place prior to this error code still occur.
QMAIL-LOCAL matches the deelivery address to the dot-qmail file that best matches by name. Delivery addresses can be of the form:
username-extention-extenstion1-...@domain.com
and the Dot-Qmail files are of the form:
.qmail-username .qmail-username-extension-default .qmail-username-extension-extension
It first tries for an exact match, then, replaces the last term by “default” and tries again. It then successively removes the right terms from the address and works down until it finds the best match. Pretty much common sense.
The advantage of the dot-qmail files is that they can be integrated with your application. Each mail address can be a “command address” to a particular object (e.g. a mailing list). Each extension (term seperated by a dash) can be a command or parameter passed into the directory for procesing.
Sending mail to other hosts
QMAIL-RSPAWN runs like qmail-lspawn.
QMAIL-REMOTE is started like qmail-local , but communicates via the SMTP protocol or the other host to send the message.
QMAIL-QMQPC is used to send a mail to a remote (or local) QMQP-enabled host for delivery. This mail does not enter the local qmail queue, but is transmitted directly from the mail application to the qmail-qmqpd program running on the remote host.
I need to finish this section later, as time permits