Linux Server How To

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


Linux Server How To - Install Sendmail From Source


Installing Sendmail From Source

Compiling Sendmail mail server from source is not anywhere near as hard as it may first sound. We will assume that the reader has no prior knowledge of compiling from source but has root privileges and the basic skills required to operate their Linux server. There are several reasons why you may want to compile sendmail from source, your chosen distribution may not have support for apt or rpm packages or you may simply require a higher level of control over the level of functionality is needed and where things are installed.

Get the Latest Sendmail Source Distribution

To compile your Sendmail mail server you will require the latest source distribution from www.sendmail.org. The easiest way to get the source distribution onto your Linux server is by using wget but alternately you may prefer to download the source elsewhere and FTP it to your server or copy it to disk or USB drive. Once you have the source distribution you should unpack it using tar and gzip into a directory on your machine so that you can start working with it. These steps are shown below, bearing in mind that $ and # should not be typed in, they are there simply to indicate a command prompt. Version 8.14.3 of Sendmail is the version we are installing, please substitute it with the latest version from www.sendmail.org.

$ mkdir /home/john/sendmail
$ cd /home/john/sendmail
$ wget ftp://ftp.sendmail.org/pub/sendmail/sendmail.8.14.3.tar.gz
$ gzip -cd sendmail.8.14.3.tar.gz | tar xvf -
$ cd sendmail-8.14.3

So on our Slackware Linux server we now have the unpacked source distribution of Sendmail and must now build it and install it. If you are logged in as a user use the su command to change to root.

Building Sendmail

The very first step we should take is to create a user and group that Sendmail can use to run its local delivery agent-

# groupadd smmsp
# useradd -g smmsp -d /var/spool/clientmqueue smmsp

Once we have created the smmsp user and group, taking care to ensure that the home directory for this user is /var/spool/clientmqueue we can change into the Sendmail source directory and commence building Sendmail.

# cd /home/john/sendmail/sendmail-8.14.3

Inside the Sendmail souce directory we can use the ls command to view its contents. There are several subdirectories that hold the key files necessary to build sendmail or one of its additional components such as libmilter, makemap or the vacation program. Sendmail and its additional components is compiled very easily by using build scripts within these subdirectories.

root@slackware-linux-server:/home/john/sendmail/sendmail-8.14.3# ls
Build* Makefile devtools/ libsmdb/ praliases/
CACerts PGPKEYS doc/ libsmutil/ rmail/
FAQ README editmap/ mail.local/ sendmail/
INSTALL RELEASE_NOTES include/ mailstats/ smrsh/
KNOWNBUGS cf/ libmilter/ makemap/ test/
LICENSE contrib/ libsm/ obj.Linux.2.6.29.6-smp.i686/ vacation/

We should start by building Sendmail though at this point we shall not install it. Change to the sendmail/ directory and execute the build command as demonstrated below-

# cd sendmail
# sh ./Build

Next we need to change to the cf/cf/ directory (no, that is not a typing error!) where you will see a number of .mc files that have been tailored to suit different systems. Select the one that describes your Linux server the best and rename it to sendmail.mc. We chose generic-linux.mc. Edit it if you wish to add additional features or change any specific configuration then build the cf file using sh ./Build sendmail.cf. It is highly recommended that if your intention is to run a production mail server with several users, multiple domains etc that you read our article on How to configure Sendmail. Install sendmail.cf by typing sh ./Build install-cf, which will place your newly built sendmail.cf into the /etc/mail directory.

# cd ../cf/cf
# cp generic-linux.mc sendmail.mc
# sh ./Build sendmail.cf
# sh ./Build install-cf

We should now install sendmail itself, change back to the sendmail/ directory and complete the install by typing sh ./Build install

# cd ../../sendmail
# sh ./Build install

For each of the remaining utilities such as makemap, mailstats, libmilter etc simply change into the appropriate directory and type sh ./build install to install it. Handy utilities that are highly recommended are libmilter, makemap, praliases and vacation. Once you have complted your install of Sendmail the final thing you may require is a startup script such as the one below to stop and start sendmail. Place the script in the /etc/rc.d/ directory of your Linux server and your Sendmail install should be ready to start.

#!/bin/sh
# Start/stop/restart sendmail.

# Start sendmail:
sendmail_start() {
if [ -x /usr/sbin/sendmail ]; then
echo "Starting sendmail MTA daemon: /usr/sbin/sendmail -L sm-mta -bd -q25m"
/usr/sbin/sendmail -L sm-mta -bd -q25m
echo "Starting sendmail MSP queue runner: /usr/sbin/sendmail -L sm-msp-queue -Ac -q25m"
/usr/sbin/sendmail -L sm-msp-queue -Ac -q25m
fi
}

# Stop sendmail:
sendmail_stop() {
killall sendmail
}

# Restart sendmail:
sendmail_restart() {
sendmail_stop
sleep 1
sendmail_start
}

case "$1" in
'start')
sendmail_start
;;
'stop')
sendmail_stop
;;
'restart')
sendmail_restart
;;
*)
echo "usage $0 start|stop|restart"
esac