Linux Server How To

How To Setup, Configure, Manage and Secure a Linux Server


Linux Server How To - Configure Sendmail


Configure Sendmail

There are two aspects to sendmail which we can configure. We can configure Sendmails behaviour such as queues, timeout intervals and additional features such as milters through sendmail.cf and submit.cf. We can also configure users, domains and relaying through the local configuration files such as aliases, local-host-names and relay-domains. This article shall endevour to familiarize the reader with changing the behaviour of Sendmail to suit their requirements. Local configuration is dealt with in our related article on Sendmail Users, Relays and Domains.

The Generic Linux sendmail.mc

The majority of Sendmail and its queue runners behaviour is determined by the sendmail.cf and submit.cf files in the /etc/mail directory. Although these files can be directly edited this is not considered best practice and the preferred method is to generate new sendmail.cf or submit.cf file using the m4 macro processor. In our tutorial on how to install Sendmail from Source we used the Build script to construct a sendmail.cf with sendmail.mc as its input file. Sendmail.mc contained a generic and very simple configuration that could be added to easily to create a more specific configuration or provide additional features. This sendmail.mc is as below.

divert(0)dnl
VERSIONID(`$Id: generic-linux.mc,v 8.1 1999/09/24 22:48:05 gshapiro Exp $')
OSTYPE(linux)dnl
DOMAIN(generic)dnl
MAILER(local)dnl
MAILER(smtp)dnl

Although this sendmail.mc when processed with the m4 macro procesor will create a sendmail.cf file that may accommodate the basic requirements of a mail server for a single domain it falls dismally short as far as more complex mail arrangements are concerned.

The sendmail.mc below this paragraph can be considered far more complete and suitable for use in a production environment or even an Internet Service Provider. It includes support for virtual users via the virtusertable, mailertable, and redirection. Additionally it also includes support for procmail, a mail preprocessing agent that is very useful for integrating anti-spam programs such as spamassassin. This sendmail.mc can be copied from this page and pasted into a putty window on your Linux server (use 'cat > sendmail.mc' or vi) where it will work on the majority of Linux distributions.

divert(0)dnl
VERSIONID(`$Id: generic-linux.mc,v 8.1 1999/09/24 22:48:05 gshapiro Exp $')
OSTYPE(linux)dnl
DOMAIN(generic)dnl
dnl FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
FEATURE(`use_cw_file')dnl
FEATURE(`use_ct_file')dnl
FEATURE(`mailertable',`hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
FEATURE(`access_db', `hash -T<TMPF> /etc/mail/access')dnl
FEATURE(`blacklist_recipients')dnl
FEATURE(`local_procmail',`',`procmail -t -Y -a $h -d $u')dnl
FEATURE(`always_add_domain')dnl
FEATURE(`redirect')dnl
MAILER(local)dnl
MAILER(smtp)dnl

Build Your Sendmail.cf

If you compiled Sendmail from source the best place in your file system to build your sendmail.cf is in the /path/to/sendmail/source/cf/cf directory, which will contain sample sendmail.mc files for a wide cross section of Unix-like operating systems and the Build scripts, makefile etc for creating your sendmail.cf. Once you have edited or created your sendmail.mc you must build your sendmail.cf by typing-

# sh ./Build sendmail.cf
# sh ./Build install-cf

If you installed Sendmail using apt-get such as we did with our Ubuntu Linux server creating a new sendmail.cf is best performed in the /etc/mail directory, though this may not be necessary depending on your specific distribution. Some distributions may require you to locate a cf/cf/ directory somewhere in /usr/src. With most apt-get Sendmail installations using m4 by itself will suffice -

# sudo m4 sendmail.mc > newsendmail.cf
# sudo cp newsendmail.cf sendmail.cf

Our Ubuntu Linux server has an excellent utility called sendmailconfig which rebuilds sendmail.conf, sendmail.cf and submit.cf for us. Our revised sendmail.mc must be in the /etc/mail directory for this utility to work properly.

# sudo sendmailconfig

Regardless of the method you need to use to rebuild your sendmail.cf or submit.cf Sendmail must be restarted for the new configuration to take effect.

Additional Features

Many special additional features can be added or tweaked through your sendmail.cf configuration file that can add extended functionality or alter the behaviour of the Sendmail daemon on your Linux server. These features are documented on the Sendmail website on the cf/README Features page. The example sendmail.mc we have documented on this page will be more than adequate for 99% of Sendmail users however if you want to explore Sendmails capabilities more or need to fine tune a particular aspect of your mail server then the cf/README provides an up to date list of special features, written by Sendmails creator himself, Eric Allman.