Sendmail

Introduction

Sendmail implements a general purpose internetwork mail routing facility. This document explain how to install sendmail and run an email server which will send and receive mail using the SMTP protocol.

An IMAP or POP3 server is required to retrieve mail using Eudora or MS Outlook. Sendmail does not offer POP3 or IMAP services.

Prerequisites

You should have a basic knowledge of UNIX and DNS.

The server should allow incoming connections to the SMTP service which will be listening on TCP port 25.

The server should have a fully qualified hostname.

The hostname should resolve to an A record.

The MX record for the domain for which you wish to receive mail should point to the hostname of your server.

There should a PTR record for the IP address of your server.

Installating sendmail

Download the sendmail source code from the sendmail website.

The sendmail binary is now installed. The next step is to configure sendmail.

Configuring sendmail

The main configuration file for sendmail is the /etc/mail/sendmail.cf file. Starting with version 8.12, sendmail uses the /etc/mail/submit.cf configuration file for mail submission. The .cf files are complex to understand. It is recommended that you create a .mc configuration file and use the M4 (macro processor) to generate the .cf file.

There are some sample .mc configuration files in the cf/cf/ directory of the sendmail source code. Alternatively, you can use one of the sample configuration files available from this website. You should edit the .mc file with a UNIX text editor such as vi.

The following sample configuration files are available for download

If you already have sendmail installed and configured, you can generate a new sendmail.cf file by using the following command:

m4 directory/m4/cf.m4 config.mc > sendmail.cf

The directory for the sendmail m4/cf.m4 file depends on the operating system you are using:

Verify whether you have the following files in /etc/mail

The local-host-names file should contain the domain name for which your mail server should accept mail. It is recommended that you also add localhost to this file. Each entry should be on a new line.

If there is no relay-domains file, create one with the following command:

touch /etc/mail/relay-domains

The aliases file should contain the following entries at least:

postmaster:   root
abuse:        root
security:     root

In the above example, postmaster is an alias for the root mailbox. The following command will generate the aliases table:

newaliases

You can create a new access file by typing

touch /etc/mail/access

The default database map type for Linux, FreeBSD, NetBSD or OpenBSD is hash. Solaris users may have to use dbm instead of hash as the database map type. Type the following to generate the tables:

makemap hash /etc/mail/access < /etc/mail/access

If you are using the smarthost.mc or smarthost-dialup.mc, create a genericstable file and type:

makemap hash /etc/mail/genericstable < /etc/mail/genericstable

You can now start sendmail.

Starting sendmail

The sendmail MTA can be started with the following command:

/usr/sbin/sendmail -L sm-mta -bd -q30m
 or
/usr/sbin/sendmail -bd -q30m (versions 8.9.x, 8.10.x, 8.11.x)

The Mail Submission Agent listens for incoming connections on TCP port 587.

If you are using sendmail 8.12 or 8.13, enter the following command to start the Mail Submission Program:

/usr/sbin/sendmail -L sm-msp-queue -Ac -q30m

Shutting down sendmail

You can shutdown sendmail by entering the following command:

kill `head -1 /var/run/sendmail.pid`

Verifying whether sendmail is running

You can verify whether sendmail is running by running the following command:

telnet localhost 25

You will see the sendmail banner which shows the version of sendmail you are using. Type quit and press enter to exit to the shell.

Mail log

The mail log is usually written to /var/log/maillog

Viewing the mail queue

You can display the contents of the mail queue with the following command:

/usr/bin/mailq

or

/usr/bin/mailq -Ac for the client mail queue

Process messages saved in the mail queue

You can process messages saved in the mail queue with the following command:

/usr/sbin/sendmail -q

or

/usr/sbin/sendmail -q -Ac for the client mail queue

sendmail configuration files

Add the domains (one per line) for which you want mail to be delivered locally to this file.

If the system is acting as a secondary MX server, add the domains (one per line) to this file.

This file is used to allow or block relaying.

Mail relaying

Mail relaying occurs when mail is forwarded from someone else through your mail server. Forwarding mail through a mail server is perfectly natural as long as either the originator of the message or the receiver is a authorized user. If neither the sender nor the recipient of the message is a local user, it is called third-party mail relaying.

Mail servers should be configured not to accept third-party mail relay. If a mail server allows third-party mail relaying from everyone, it is known as an open relay. Such a mail server attracts spammers as it can be used to send large amounts of junk mail under false identity.

If the client computer from which you are connecting from has a static IP address, you can add the following entry, for example, to allowing relaying (send mail):

192.168.0.5 <TAB> RELAY (allows 192.168.0.5 to relay)

192.168.1 <TAB> RELAY (allows 192.168.1/24 to relay)

172.16.0.1<TAB> REJECT (rejects connections from 172.16.0.1)

You should run the makemap command after modifying the access file.

Linux/BSD - makemap hash /etc/mail/access < /etc/mail/access

Solaris - makemap dbm /etc/mail/access < /etc/mail/access

If you are connecting from a dynamic IP address, you should use SMTP AUTH to allow relaying.

Mail submission

Sendmail has been split into two parts, with one part handling mail submission. This allows sendmail to run without being SUID root.

The Mail Submission Program (MSP) uses the /var/spool/clientmqueue directory by default. It will use the /etc/mail/submit.cf configuration file. That configuration file can be generated from the submit.mc using m4.

The MSP will send outgoing mail by passing it to localhost on port 25 using the SMTP protocol. As of sendmail version 8.12.x, you should have sendmail running as a daemon and listening on localhost at least to allow delivery of local mail.

Acronyms

LDA   Local Delivery Agent a program that a mail server uses to deliver mail messages to the mailboxes of users. This program is also known as local mailer (e.g. mail, procmail).

MUA Mail User Agent a program that a user uses to process mail messages (e.g. MS Outlook, Eudora, Pine, Mutt).

MTA  Mail Transfert Agent a program that a mail server uses to send and receive mail messages using SMTP (e.g. sendmail).

MSA  Mail Submission Agent.

MSP  Mail Submission Program.

SMTP  Simple Mail Transfer Protocol

References

Anti-Spam Recommendations for SMTP MTAs (RFC 2505)


http://megawatt.resistor.net/~sm/sendmail/index.html © sm