How to configure Sendmail

Posted on 8:29 PM by Bharathvn

Configuring Sendmail
The /etc/mail/ 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 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/ Listing 8.1 shows an example of this file's contents.

A fragment of the /etc/mail/ 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/ by running the
dnl # following command:
dnl #
dnl # m4 /etc/mail/ > /etc/
dnl #
VERSIONID('linux setup for ASPLinux')dn1
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')

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

I will be mostly considering parameters that have to be set in the file; if a 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: 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 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

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: 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).