Personal tools
You are here: Home User Contributed Files Sendmail
Document Actions

Sendmail

by Neil Schneider last modified 2005-04-30 03:30
Sendmail Presentation
Neil Schneider October 11, 2001

MUA Versus MTA

Mail user agents are the programs you use on your local machine. Things like pine, mutt, Outlook and Eudora. There can be mutliple MUAs on a single system.

MTAs like sendmail move the mail from a local server to a remote server, and receive mail from remote servers. Usually there is only one MTA on a server. MTA's include Sendmail, qmail, Postfix and Smail.

Why is sendmail so complex?

Sendmail needs to transport mail between a large variety of machines on many different networks and to a wide variety of systems. Therefore it is designed with a lot of flexibility. If it only needed to deliver to a local system, it would be fairly simple. Delivery to the internet requires it to use the DNS system, to look up hostnames. Sendmail also delivers through UUCP and over BITNET, which adds more complexity.

Three Important Parts

Sendmail is composed of several parts, programs, configuration files, and directories.

The Configuration File

The configuration file is one of the most important parts of sendmail. It contains instructions on how mail is handled. Rewriting rules transform headers for different deliveries. The configuration file is optimized for the program, which makes it sometimes difficult for humans to read. There are rewriting rules in the configuration file for changing the mail headers to prepare the mail for various forms of transport. On most Linux systems the configuration file is /etc/sendmail.cf.

The Queue

Not all mail gets delivered immediately. The queue is where mail is stored before transport, or if delivery is delayed.

Mail can be delayed if the remote server is temporarily unavailable. In that case sendmail will hold the mail in the queue, until the server becomes available.

If there are multiple recipients, some mail may be delivered immediately while other copies are delayed. A mailing list might be an example of this.

When mail delivery ie expensive. Mail delivery could be delayed until phone rates are cheaper.

The server could be attached to a network on a temporary basis, such as on a dial-up connection. Mail can be delayed until the connection comes up.

Aliases and Mailing Lists

Aliases allow mail addressed to on address to be sent to another address. Mail can be piped through programs like mailinglist software, to be further processed before delivery. The /etc/aliases file contains the aliasing rules. Individual users can use aliasing through mechanisms like vacation and .forward files to redirect mail.

Run Sendmail By Hand

It would be rare for a user to run sendmail from the command line. Usually they use some program like a MUA to compose then hand off the mail to sendmail for delivery.

It's perfectly legal to run sendmail by hand. Many system administrators will run it from command line, to test for errors.

Here's an example of running sendmail from the command line. Even if you have no intention of running a mail server, you can experiment on your own system.

In this example, I created a file, called sendstuff in my home directory.

This is a one line mail message.

Then I used the following command to mail it to myself sendmail pacneil < sendstuff

I ran sendmail directly, creating a locally delivered message on the system. Any commandline arguments not preceded by a - are considered to be email addresses.

The mail I received looked like this.

 Return-Path: <pacneil@linuxgeek.net>
 Delivered-To: pacneil@linuxgeek.net
 Received: by mail.linuxgeek.net (Postfix, from userid 500)
           id 87028104CE0; Thu, 11 Oct 2001 01:27:50 -0700 (PDT)
 Message-Id: <20011011082750.87028104CE0@mail.linuxgeek.net>
 Date: Thu, 11 Oct 2001 01:27:50 -0700 (PDT)
 From: pacneil@linuxgeek.net (Neil Schneider)
 To: undisclosed-recipients:;

 This is a one line mail message.

The Header

You notice there are eight lines of text, not in the orginal message. These lines, called the header, were added by my mail server.The last line is the original message and is called the body. The body is separated from the header, by one blank line. Notice that most of the lines in the header begin with a word, followed by a colon. These words tell what kind of information is in that line. There can be much more optional information in the header, including things like routing information and reply-to information. All the header information in this message were added by the MTA and are required headers.

The Body

The body of the email consists of everything following the first blank line, to the end of the file.

The Envelope

To handle delivery to many recipients, Sendmail uses the concept of an envelope. This is analagous to the envelopes that we use for "snail" mail. The To: Cc: and Bcc: parts of the header are the envelope.

The sendmail.cf File

The lines of the sendmail.cf file have been described in various derogatory terms. Some descriptions include modem noise chicken scratchings and swear words from a comic strip.

The following lines can definitely intimidate a new sendmail user.

 R< > $+  < $H > $1  $: < $H >  $1   try hub
 R< > $+  $: < $R > $1               try relay

The sendmail.cf file is read and parsed every time sendmail starts. It contains information that sendmail needs to run. It contains the lists and locations of various files as well as specifying permissions for those files. Most importantly it contains the rules sendmail uses to rewrite envelopes and headers, as well as rules for delivery. The minimal sendmail.cf is an empty file.

Overview of sendmail.cf

I'll not try to turn this into a tutorial on configuring a sendmail.cf file. However here are some highlights of the various components

Mail Delivery Agents

The M command defines the delivery agent. Here's a line declaring the use of procmail for the local delivery.

 Mprocmail    P=/usr/bin/procmail, F=DMSPhnu9 S-EnvFromSMTP/HdrFromSMTP, R=EnvToSmtp/HdrFromSmtp,
         T=DNS/RFC822/X=Unix,
         A=procmail -Y -m $h $g %u

This tells sendmail to use the procmail command to deliver local mail. The parameters apply to the procmail comman, and will be covered in a future presentation about procmail.

Macros

A macro allows you to define a value once then reference it symbolically by using the letter or curly-brace-enclosed multiple characters elsewhere.

 # who I send unqualified names to (null means deliver locally)
 DRkernel-panic.org
 D{Remote}kernel-panic.org

The R and {Remote} are macros names that have the string kernel-panic.org as their value. You can access those values later in the sendmail.cf with expressions like $R and ${Remote}.

Rules

At the heart of the sendmail.cf are the sequences of rules that rewrite or transform mail address from one form to another. This is necessary because addresses must conform to many different standards for different deliveries and networks.

 R$-                       $@ $1 @ $R                 user -> user @ remote

Mail addresses are compared to the rule no the left ($-). If they match the rule, they are rewrittten on the basis of the rule on the right ($@ $1 $@ $R). The text on the right is a comment, and doesn't require a leading #.

Because rewriting may require several steps, rules are organized into sets, which can be thought of as subroutines. The S command begins a rule set:

         S3

Class Macros

There are times when a single text value of a D command (macro definition) is not sufficient. Often you will want to define a macro to have multiple values and view those values as elements of an array. The C command defines a class macro. A class macro is like an array that can hold many values. The name of a class macro is either a single letter or, a curly-brace-enclosed multcharacter name:

CW localhost fontserver          <- a single letter
C{My_Names} localhost fontserver         <- multiple characters

File Class Macros

To make administration easier, it is often convenient to store long or volatile lists of values in a file. The F sendmail.cf command defines a file class macro. It is just like the C command above, except that the array values are taken from a file.

Fw/etc/mail/local-host-names

Here the file class macro w obtains its values from the file /etc/mail/local-host-names

Options

Options tell sendmail many useful and necessary things. They specify the location of key files, set timeouts, and divide how sendmail will act and how it will dispose of errors. They can be used to tune sendmail to meet your needs.

The O command is used to set sendmail options.

# location of alias file
O AliasFile=/etc/aliases

Here the O option defines the name of the aliases file.

Headers

Mail messages are composed of two parts: a header followed by a blank line and then the body. The body may contain virtually anything. With the advent of MIME (Multipurpose Internet Mail Extensions), the message body can now be composed of many mime messages, each with its own MIME header and sub-body. The header, on the other hand must contain lines of information that conform to certain standards. The H command is used to specify which mail headers to include in a mail message and how they will look:

HReceived: $?sfrom $s $.$?($?s$|from $.$)

This particular H command tells sendmail that a Received: header line must be added to the header of every mail message.

Priority

Not all mail has the same priority. Mass mailings (to mailing list for example) should be transmitted after mail to individual users. The P command sets the beginning priority for a mail message. The priority is used to determine a message's order when the mail queue is processed.

Pjunk=-100

This particular P command tells sendmail that mail with a Precedence: header line of junk should be processed last.

M4 Configuration

the days when configurtion of sendmail required and intimate knowledge of every line in the sendmail.cf file are behind us, thanfully. This practice is no longer recommended. New features may be ignored if you edit the sendmail.cf directly.

The m4 Preprocessor

Creating a configuration file with m4 is simple. Several samples are included in most Linux distributions. You must have the sendmail.cf rpm installed on Red Hat and Mandrake to install these sample files. The files on older Red Hat systems were stored in /usr/lib/sendmail-cf on newer versions it's in /usr/share/sendmail-cf You run m4 from the cf subdirectory. Here's the directory listing of /usr/share/sendmail-cf/ from my system:

cf domain feature hack m4 mailer ostype README sh siteconfig

Of special interest in the cf directory are those mc files that begin with generic, because these contain boilerplates for developing your own mc files. The accepted file naming convention is to name your m4 configuration file with a .mc extension. When you preprocess your .mc file you output to the .cf file. If you use this convention it will be easier to seperate your pre-preprocessor files from your post-preprocessor files. Here is a copy of the redhat.mc that comes with the distribution. For most new users this is a good starting place.

*********************
divert(-1)
dnl This is the sendmail macro config file. If you make changes to this file,
dnl you need the sendmail-cf rpm installed and then have to generate a
dnl new /etc/sendmail.cf by running the following command:
dnl
dnl m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
dnl
include(`../m4/cf.m4')
VERSIONID(`linux setup for Red Hat Linux')dnl
OSTYPE(`linux')
define(`confDEF_USER_ID',``8:12')dnl<BR> undefine(`UUCP_RELAY)dnl
undefine(`BITNET_RELAY')dnl
define(`confAUTO_REBUILD')dnl
define(`confTO_CONNECT', `1m')dnl
define(`confTRY_NULL_MX_LIST',true)dnl
define(`confDONT_PROBE_INTERFACES',true)dnl
define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`STATUS_FILE', `/var/log/sendmail.st')dnl
define(`UUCP_MAILER_MAX', `2000000')dnl
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`confAUTH_OPTIONS', `A')dnl
dnl TRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
dnl define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
dnl define(`confTO_QUEUEWARN', `4h')dnl
dnl define(`confTO_QUEUERETURN', `5d')dnl
dnl define(`confQUEUE_LA', `12')dnl
dnl define(`confREFUSE_LA', `18')dnl
dnl FEATURE(delay_checks)dnl
FEATURE(`no_default_msa',`dnl')dnl
FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
FEATURE(`mailertable',`hash -o /etc/mail/mailertable')dnl
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable')dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(local_procmail)dnl
FEATURE(`access_db')dnl
FEATURE(`blacklist_recipients')dnl
EXPOSED_USER(`root')dnl
dnl This changes sendmail to only listen on the loopback device 127.0.0.1
dnl and not on any other network devices. Comment this out if you want
dnl to accept email over the network.
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
dnl We strongly recommend to comment this one out if you want to protect
dnl yourself from spam. However, the laptop and users on computers that do
dnl not have 24x7 DNS do need this.
FEATURE(`accept_unresolvable_domains')dnl
dnl FEATURE(`relay_based_on_MX')dnl
MAILER(smtp)dnl
MAILER(procmail)dnl

*******************

To build a redhat.cf file, in the current directory from this redhat.mc file, we simply run the m4 preprocessor on the file like this:

     m4   redhat.mc   >   redhat.cf

Debuggin with -d

The sendmail program offers a command-line swich for investigating and solving mail problems. The debugging -d switch allows you to observe sendmail's inner working in detail

The form of the -d command-line switch is

-dcategory,level,category.level,....
-dANSI

The -d may appear alone, or it may be followd by one or more category.level pairs seperated by commas or, beginning with V8.8, by the word ANSI.

The category limits debugging to an aspect of sendmail (such as queueing or aliasing). The level limits the verbosity of sendmail (with low levels producing the least output).

The category is either a positive integer or a range of integer values specified as

        first-last

When category is a range, first is a positive integer that specifies the first category in the range. It is followed by a hyphen character (-) and then last, a positive integer that specifies the last category in the range. The value of first must be less than the value of last, or the range will be ignored.

Begining with V8.8 sendmail a special debugging word can be specified at the command line to cause debugging output to become clearer:

        -dANSI         <- V8.8 and above

ANSI causes defined macro, class macros, and operators to be displayed in reverse video.

Rule-Set Testing with -bt

Sendmail offers a mode of operation (called rule set testing mode) that allows you to observe the flow of addresses through the rule set. The -bt command line switch causes sendmail to run in rule-testing mode. This mode is interactive. You enter rules set numbers, addresses and other commands, and sendmail processes them and prints the results. The -bt switch's primary use is in testing changes in the configuration file. It also is useful for learning how rules and rule sets work

The following command runs sendmail in rule-testing mode:

/usr/sbin/sendmail -bt

At first, the output produced by this command line prompts you like this:

ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)

Enter

To see a summary of the the functions of the rule-testing mode, at this point, enter a ? character followed by a at the > prompt. The output lists each function, and gives a brief description.

Summary

I have attempted to give a brief overview of the functions and use of sendmail. Though it is not a complete tutorial I hope that it provides enough information to help you understand how sendmail functions and it's unique features

Links

Here are some links you can use to read more on-line about sendmail.

Sendmail.org the primary souce for information on Sendmail

Sendmail.net A news and discussion forum for Sendmail open source.

"Claus AƟmann's collection":http://www.sendmail.org/%7Eca/email/misc.html of hints about email.

Wouter Hanegraaff describes how to configure sendmail for users who do not have a direct Internet connection but use a dial-up account with an ISP.

Nitin Mules Installing sendmail from source on Linux"http://www3.sympatico.ca/nitin.mule/sendmail.html

« May 2019 »
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: