How to configure Sendmail

Configuring Sendmail
The /etc/mail/sendmail.cf file is the server's main configuration file. The sendmail server has a bad reputation because it is difficult to configure. Having taken even a brief look at the file's contents, you may feel intimidated by its more than 1,000 lines of information. The mysterious options and parameters only intensify the feeling.

All settings in the sendmail.cf configuration file are grouped into sections. A section is preceded by a header that looks like the following:

##################
# local info #
##################


These comments indicate that the local info section follows them. Some of the sections are the following:

Local info — Contains local information and the main information about the server and domain

Options — Contains operational settings

Message precedence

Trusted users

Format of headers

It is impossible to consider all of the sendmail configuration settings in this book; it would require a separate book to describe each of its parameters. The goal of this book is to teach you some techniques to enhance the efficiency and security of your system; therefore, I will only consider the settings related to these aspects and how to use sendmail.

To make configuring sendmail easier, the latest versions of this service use a new configuration file: /etc/mail/sendmail.mc. Listing 8.1 shows an example of this file's contents.

A fragment of the /etc/mail/sendmail.mc file


divert (-1)
dnl # This is the sendmail macro config file. If you make changes
dnl # to this file, you need the sendmail-cf rpm installed and then
dnl # have to generate a new /etc/sendmail.cf by running the
dnl # following command:
dnl #
dnl # m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
dnl #
include('/usr/share/sendmail-cf/m4/cf.m4')
VERSIONID('linux setup for ASPLinux')dn1
OSTYPE('linux')
dnl # Uncomment and edit the following line if your mail needs to be
dnl # sent out through an external mail server:
dnl define('SMART_HOST','smtp.your.provider')
define('confDEF_USER_ID',"8:12")dnl
undefine('UUCP_RELAY')dnl
undefine('BITNET_RELAY')dnl
...
...




The format of the sendmail.mc file is simpler than that of the old sendmail.cf file, which reduces the chances of making a configuration error. After editing the sendmail.mc file, it has to be converted into the CF format with a special command to turn it into the sendmail.cf file.

I will be mostly considering parameters that have to be set in the sendmail.cf file; if a sendmail.mc file parameter is described, this will be stated explicitly.

In Chapter 2, I mentioned that Linux may hang at boot when starting the sendmail service. This happens because the mail server cannot determine the name of your computer. Open the /etc/hosts file. In most cases, there will be only one entry in it:

127.0.0.1 localhost.localdomain localhost

This file is described in more detail in Chapter 11, where DNS is considered. For now, it will suffice to know that this entry maps IP address 127.0.0.1 to the localhost computer name. In any system, these address and name indicate the local machine. When the localhost name is specified in network applications, this name is converted to IP address 127.0.0.1.

The sendmail program uses the name of the computer specified when Linux was installed as the local machine name. If you have forgotten what this name is, you can use the hostname command to refresh your memory. My machine is named FlenovM. Because sendmail cannot determine the IP address of the machine named FlenovM, it hangs the system. The problem can be fixed by adding the following entry to the /etc/hosts file:

192.168.77.1 FlenovM FlenovM

Replace FlenovM with the name of your computer and specify its IP address. Now, sendmail can be placed into the start-up and it will work without a hitch even using default settings.

Each new user is automatically created a mailbox with the same name as the user name. Mailbox files for all users are stored in the /var/spool/mail directory. Thus, the mailbox for the root user is located in the /var/spool/mail/root file.

For working with mail, you need a mail client to send and receive messages to and from the server. There is a host of such programs; some Linux distributions offer up to seven clients. Which one you choose is up to you and your preferences.

You can do without a mail client and connect to the server directly using the Telnet service, especially because Telnet commands are quite simple and easy to use. When using Telnet, mail is sent using port 25 (the SMTP port) and received at port 110 (the POP3 port).