Chapter 13. Sendmail

Table of Contents
13.1. Introduction
13.2. Installation
13.3. Configuration

13.1. Introduction

Sendmail is the default Mail Transfer Agent (MTA) that Slackware Linux uses. sendmail was originally written by Eric Allman, who still maintains sendmail. The primary role of the sendmail MTA is delivering messages, either locally or remotely. Delivery is usually done through the SMTP protocol. The means that sendmail can accept e-mail from remote sites through the SMTP port, and that sendmail delivers site destined for remote sites to other SMTP servers.

13.2. Installation

Sendmail is available as the sendmail package in the "n" disk set. If you want to generate your own sendmail configuration files, the sendmail-cf package is also required. For information about how to install packages on Slackware Linux, refer to Chapter 18.

You can let Slackware Linux start sendmail during each boot by making the /etc/rc.d/rc.sendmail executable. You can do this by executing:


# chmod a+x /etc/rc.d/rc.sendmail
    

You can also start, stop and restart sendmail by using start, stop, and restart as a parameter to the sendmail initialization script. For example, you can restart sendmail in the following way:


# /etc/rc.d/rc.sendmail restart
    

13.3. Configuration

The most central sendmail configuration file is /etc/mail/sendmail.cf; this is where the behavior of sendmail is configured, and where other files are included. The syntax of /etc/mail/sendmail.cf is somewhat obscure, because this file is compiled from a much simpler .mc files that uses M4 macros that are defined for sendmail.

Some definitions can easily be changed in the /etc/mail/sendmail.cf file, but for other changes it is better to create your own .mc file. Examples in this chapter will be focused on creating a customized mc file.

13.3.1. Working with mc files

In this section we will look how you can start off with an initial mc file, and how to compile your own .cf file to a cf file. There are many interesting example mc files available in /usr/share/sendmail/cf/cf. The most interesting examples are sendmail-slackware.mc (which is used for generating the default Slackware Linux sendmail.cf), and sendmail-slackware-tls.mc which adds TLS support to the standard Slackware Linux sendmail configuration. If you want to create your own sendmail configuration, it is a good idea to start with a copy of the standard Slackware Linux mc file. For instance, suppose that we would like to create a configuration file for the server named straw, we could execute:


# cd /usr/share/sendmail/cf/cf
# cp sendmail-slackware.mc sendmail-straw.mc
      

and start editing sendmail-straw.mc. After the configuration file is modified to our tastes, M4 can be used to compile a cf file:


# m4 sendmail-straw.mc > sendmail-straw.cf
      

If we want to use this new configuration file as the default configuration, we can copy it to /etc/mail/sendmail.cf:


# cp sendmail-straw.cf /etc/mail/sendmail.cf
      

13.3.2. Using a smarthost

If you would like to use another host to deliver e-mail to locations to which the sendmail server you are configuring can not deliver you can set up sendmail to use a so-called "smart host". Sendmail will send the undeliverable e-mail to the smart host, which is in turn supposed to handle the e-mail. You do this by defining SMART_HOST in your mc file. For example, if you want to use smtp2.example.org as the smart host, you can add the following line:


define(`SMART_HOST',`stmp2.example.org')
      

13.3.3. Alternative host/domain names

By default sendmail will accept mail destined for localhost, and the current hostname of the system. You can simply add additional hosts or domains to accept e-mail for. The first step is to make sure that the following line is added to your mc configuration:


FEATURE(`use_cw_file')dnl
      

When this option is enabled you can add host names and domain names to accept mail for to /etc/mail/local-host-names. This file is a newline separated database of names. For example, the file could look like this:


example.org
mail.example.org
www.example.org
      

13.3.4. Virtual user table

Often you may want to map e-mail addresses to user names. This is needed when the user name differs from the part before the "@" part of an e-mail address. To enable this functionality, make sure the following line is added to your mc file:


FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
      

The mappings will now be read from /etc/mail/virtusertable.db. This is a binary database file that should not directly edit. You can edit /etc/mail/virtusertable instead, and generate /etc/mail/virtusertable.db from that file.

The /etc/mail/virtusertable file is a simple plain text file. That has a mapping on each line, with an e-mail address and a user name separated by a tab. For example:


[email protected]    john
[email protected]        john
      

In this example both e-mail for [email protected] and [email protected] will be delivered to the john account. It is also possible to deliver some e-mail destined for a domain that is hosted on the server to another e-mail address, by specifying the e-mail address to deliver the e-mail to in the second in the second column. For example:


[email protected]    [email protected]
      

After making the necessary changes to the virtusertable file you can generate the database with the following command:


# makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable