11.5 Serialmail

Qmail was designed for an environment with fairly fast network connections, where the roundtrip delay on a connection dominates the data transfer time, so it's faster to have multiple single-recipient deliveries in progress that can share the connection. In environments where this is not true, the serialmail add-on package delivers one message at a time. It's also useful to deliver mail to hosts via intermittent dialup connections.

To use serialmail, first configure qmail to deliver mail to a Maildir, then run programs from the serialmail package to take mail out of the Maildir and send it across the Net. You can run it on a schedule to push out mail to a slow host or on demand to send mail when a dialup host connects.

The serialmail package is installed the same way as other DJB software. It depends on the tcpclient program that is in the UCSPI package. (That's the same package that contains tcpserver, so you should already have it installed.) The most useful programs in the package include:


maildirserial

The driver program that selects messages from a Maildir, calls another program to try to deliver them, and deals with the results


serialsmtp

The actual SMTP client called indirectly from maildirserial


maildirsmtp

A shell wrapper that calls maildirserial to deliver the files in a directory via SMTP


setlock

Runs a program with a file locked to ensure that multiple copies of the program aren't running simultaneously

To deliver mail to a domain with serialmail, first define the domain as a virtual domain and deliver all its mail into a Maildir. If you want to handle the domain bad.example.com, add a line to virtualdomains like this:

bad.example.com:alias-badex

Then create ~alias/.qmail-badex-default, containing ./bemaildir/, to deliver all of the mail for that domain into bemaildir.

Then, when it's time to deliver the mail, run a command like this:

setlock bemaildir.lock \  maildirsmtp bemaildir alias-badex- 10.2.3.4 my.example.com 2>&1 |     splogger serial

The setlock command uses bemaildir.lock as a semaphore to keep a new delivery session from starting if a previous one hasn't finished yet. It runs maildirsmtp to do the deliveries. To find messages to deliver, it looks in bemaildir for files with Delivered-To: lines starting with alias-badex-, which is the string that the virtual domain alias prefixes to mail delivered there. (It ignores files with other Delivered-To: lines, so you can store mail for several different domains in the same Maildir, running maildirsmtp with different address prefixes.) It connects to IP address 10.2.3.4 to deliver the mail, and in the SMTP session uses my.example.com as the argument to the HELO command, which should be the name of this machine. The messages are sent by SMTP, with the envelope recipient addresses being the ones in the Delivered-To: lines with the alias-badex- removed, so the mail is redelivered to the original addresses.

All of the details are handled by maildirserial: finding the files, passing their names to smtpserial, checking the return codes and deleting the files if the delivery was successful, sending back a bounce if the delivery failed and the file has been there too long, and leaving the file for another try otherwise.

11.5.1 Using Serialmail

If you're delivering to a slow host at a fixed address, the easiest way to push out the mail is to run maildirsmtp from cron on a suitable schedule. Run it once an hour, or if the remote host is busier at some times of day than others, run hourly during the slow part of the day.

If you're delivering to a host that connects intermittently via dialup, start maildirsmtp from the script that runs when the remote host connects. Typically the script will have a variable like $REMOTE with the current IP address of the remote, which you can use in the call to maildirsmtp. If the host stays connected for a long time, you may want to push out mail periodically while it's connected. There's no elegant way to do that, but see Chapter 18 for an example of a serviceable approach.

If your host is one that dials into a hub, you can also use maildirsmtp. In virtualdomains set a catch-all route to put all outgoing mail into a Maildir:

:alias-catchall

with ~alias/.qmail-catchall delivering into the maildir. Then run maildirsmtp from the dialout startup script to send your mail to the hub. Again, if you stay connected for a long time, you may want to run it periodically while you're connected.



qmail
qmail
ISBN: 1565926285
EAN: 2147483647
Year: 2006
Pages: 152

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net