

Sendmail Made Easy!

By Eberhard W. Lisse

All Linux distributions come with a Mail Transfer Agent (the program that does the routing and sending of the messages. The daddy of them all is sendmail (http://www.sendmail.org/).

sendmail is usually preconfigured, but if you need to set up a special situation (for example UUCP), it can become quite a nuisance. The reason for this is that at the initial writing of sendmail the configuration language was designed to parse quickly at the expense of being cryptic. I looked at a sendmail.cf in 1987 and didn't look again for 10 years.

smail is easier to understand and has always had the nice feature of batching messages, running the batches through gzip and sending the jobs off via UUCP. Saved me quite a lot of money in phone bills over the years.

However, a year and a half ago I found a package called BSMTP (Batched Simple Mail Transport Protocol) for taking care of the batch-gzipping stuff. BSMTP is a package which is used with UUCP. sendmail uses the SMTP Protocol if sending or reeiving mail via TCP/IP, but you can also feed mail into sendmail directly using this protocol. Now this package will take outgoing mail, put many messages in batches with SMTP commands inserted between messages, gzip the batches and hand them to UUCP for transport. On the other end the process is reversed, uucp receives, hands to an uncompressor which feeds to sendmail. This results in a compression of better then half. Using advanced features of the uucp on Linux you can achieve very high throughputs. BSMTP works with both smail and sendmail and has a macro package which makes sendmail configuration much easier. I like to tinker so I tried it. It took about a weekend to get sendmail working with BSMTP/UUCP. Once I had figured out the basics, it became much easier, I only needed about an hour to set it up for my leased line.

Since you have Linux, you have all the tools required. If not, install them from your distribution. I'll assume you have a working DNS with MX entries for our system and are connected by a leased line. Install the latest sendmail and sendmail-cf RPMs in the /usr/lib/sendmail-cf directory.

Consider the following few lines in a file called linux.mc located in /usr/lib/sendmail-cf/cf:

define(`confCW_FILE', `-o /etc/sendmail/sendmail.cw')
FEATURE(mailertable,`hash -o /etc/sendmail/mailertable.db')
It's rather cryptic--or is it?

Run this file through the m4 command by typing:

m4 ../m4/cf.m4 linux.mc > sendmail.cf
It produces a sendmail.cf of approximately 1200 lines (still unreadeable to me) which has been in production use on my system.

Now let's have a look at what those lines mean.

# divert(-1)
This line is a directive to the macro processor which I have never bothered to understand. It has something to do with suppressing newline characters.

Now, that's fairly easy, right? Well, what it doesn't tell you is that the local delivery program mail.local from the sendmail distribution needs to be in /bin or your mail will disappear without a trace.

What on earth is a CW file?

I receive a lot of mail to the address of el@lisse.na; however, the host name is linux.lisse.na. No problem, we have an appropriate MX entry pointing lisse.na to linux.lisse.na, right? Wrong. You must tell sendmail the names under which it can receive mail on the local host. For example:

When doing this is overlooked, sendmail sends an error message which is somewhat misleading. The bouncing message has the following Subject: line:
Subject: Returned mail: Local configuration error
And the MX list line is what is confusing:
554 MX list for nws.com.na. points back to linux.lisse.na
554 el@nws.com.na... Local configuration error

This line is only required if you have special delivery situations. For example, to use the BSMTP package to deliver mail for Triple A, Inc. via the UUCP neighbour bbbbb, set up an MX entry in the DNS and write something like this in the mailertable file:

.aaa.com.na	bsmtp:bbbbb
aaa.com.na	bsmtp:bbbbb
A TAB character is in between the pairs, and you must run a program from the sendmail package called makemap on the file mailertable to produce the binary database file mailertable.db. For example:

makemap hash < mailertable mailertable
There are other database systems (for example, dbm) but let's not complicate matters.

This line redefines the local mailer to be procmail. You most definitely want that.

This line defines the status file. Make sure you have created this directory as root.

procmail was written by Stefan van der Berg at my alma mater and deserves its own article. In short it is the local delivery program. Its strength lies in its message filtering capabilities. Very nice for those mailing lists.

Please note that I have left out the bsmtp entry that would be required, if you had used a BSMTP entry in the mailer table. If you had a UUCP neighbour, you'd need a mailer entry too which must come after smtp.

Now, test this configruation file, copy it to the /etc directory after making a backup copy of the old one and restart sendmail. As root, I use the command:

killall -HUP sendmail
I did not show you how to set up sendmail for UUCP, BSMTP, anti-SPAM or virtual domains. However, now that you have mastered the basics, it will be fairly easy.

Copyright © 1998, Eberhard W. Lisse
Published in Issue 34 of Linux Gazette, November 1998