Home arrow Site Administration arrow Page 12 - Getting Started with Sendmail

1.9 Testing a New Configuration - Administration

If you want to build or customize a sendmail configuration, you need to know your way around the sendmail distribution. This article will help you find your way around the cf directory, which contains the configuration files. It was excerpted from chapter one of The Sendmail Cookbook, written by Craig Hunt (O'Reilly Media, 2004; ISBN: 0596004710).

  1. Getting Started with Sendmail
  2. The cf directory structure
  3. The cf/m4 directory
  4. 1.1 Downloading the Latest Release
  5. 1.2 Installing sendmail
  6. 1.3 Compiling sendmail to Use LDAP
  7. 1.4 Adding the regex Map Type to sendmail
  8. 1.5 Compiling sendmail with SASL Support
  9. 1.6 Compiling sendmail with STARTTLS Support
  10. 1.7 Compiling in STARTTLS File Paths
  11. 1.8 Building a sendmail Configuration
  12. 1.9 Testing a New Configuration
  13. 1.10 Logging sendmail
By: O'Reilly Media
Rating: starstarstarstarstar / 26
July 07, 2005

print this article




You need to test the sendmail configuration before it is deployed.


Use the sendmail command-line options -bt, -bv, and -v.


At the end of Recipe 1.8, the newly created sendmail.cf is copied over the old configuration. Do not copy a customized configuration into the /etc/mail directory until it is thoroughly tested. sendmail provides excellent test tools that are used extensively in this book.

The single most important tool for testing sendmail is sendmail itself. When started with the -bt command-line option, sendmail enters test mode. While in test mode, sendmail accepts a variety of commands that examine the configuration, check settings, and observe how email addresses are processed by sendmail. Table 1-2 lists the commands that are available in test mode.

Table 1-2. sendmail test mode commands

rulesets addressProcess the address through the comma-separated list of rulesets.
=SrulesetDisplay the contents of the ruleset.
=MDisplay all of the mailer definitions.
$vDisplay the value of macrov.
$=cDisplay the values in classc.
.DvvalueSet the macrovtovalue.
.CcvalueAddvalueto classc.
-dvalueSet the debug level tovalue.
/tryflagsflagsSet the flags used for address processing by/try.
/trymailer addressProcess the address for the mailer.
/parseaddressReturn the mailer/host/user delivery triple for the address.
/mxhostnameLookup the MX records forhostname.
/mapmapname keyLook upkeyin the database identified bymapname.
/quitExit address test mode.

Several commands (=S, =M, $v, and$=c) display current sendmail configuration values defined in the sendmail.cf file, and the /map command displays values set in the sendmail database files. The -d command can be used to change the amount of information displayed. A great many debug levels can be set by -d, but only a few are useful to the sendmail administrator. All of the debug values are covered in the sendmail book, and a few of the most useful values are discussed in this book.

Two commands, .D and .C, are used to set macro and class values in real time. Use these commands to try alternate configuration settings before rebuilding the entire configuration.

Two commands display the interaction between sendmail and DNS. /canon displays the canonical name returned by DNS for a given hostname. /mx shows the list of mail exchangers returned by DNS for a given host.

Most of the remaining commands process an email address through sendmail’s rewrite rules. /parse displays the processing of a delivery address and shows which mailer is used to deliver mail sent to the address. /try displays the processing of addresses for a specific mailer. (The /tryflags command specifies whether the sender or the recipient address should be processed by the /try command.) Use the ruleset address command to display the processing of an address through any arbitrary list of rulesets that you wish to test.

The following example uses sendmail test mode to check the configuration created in Recipe 1.8. Invoke the sendmail command with the -bt option to enter test mode and the -C option to specify the configuration file to be tested. If the -C option is not used, the current configuration file (/etc/mail/sendmail.cf) is the configuration that is tested.

The following test displays the mailer configuration in the form of a list of sendmail.cfM commands:

  # sendmail -bt -C/usr/local/src/sendmail-8.12.9/cf/cf
  ADDRESS TEST MODE (ruleset 3 NOT automatically invoked) 
  Enter <ruleset> <address>
  > =M
  mailer 0 (prog): P=/bin/sh S=EnvFromL/HdrFromL R=EnvToL/HdrToL M=0 U=0:0
F=9DFMeloqsu L=0 E=\n T=X-Unix/X-Unix/X-Unix r=100
                   A=sh -c $u
  mailer 1 (*file*): P=[FILE] S=parse/parse R=parse/parse M=0 U=0:0
                     F=9DEFMPloqsu L=0 E=\n T=X-Unix/X-Unix/X-Unix r=100
                     A=FILE $u
mailer 2 (*include*): P=/dev/null S=parse/parse R=parse/parse M=0 U=0:0
                        F=su L=0 E=\n T=<undefined>/<undefined>/<undefined>
                        r=100 A=INCLUDE $u
  mailer 3 (local): P=/usr/bin/procmail S=EnvFromL/HdrFromL R=EnvToL/HdrToL
                    M=0 U=0:0 F=/59:@ADFMPSfhlnqsw| L=0 E=\n
                    T=DNS/RFC822/X-Unix r=100 A=procmail -Y -a $h -d $u
  mailer 4 (smtp): P=[IPC] S=EnvFromSMTP/HdrFromSMTP R=EnvToSMTP/EnvToSMTP
                   M=0 U=0:0 F=DFMXmu L=990 E=\r\n T=DNS/RFC822/SMTP r=100
                   A=TCP $h
  mailer 5 (esmtp): P=[IPC] S=EnvFromSMTP/HdrFromSMTP R=EnvToSMTP/EnvToSMTP
                    M=0 U=0:0 F=DFMXamu L=990 E=\r\n T=DNS/RFC822/SMTP r=100
                    A=TCP $h
  mailer 6 (smtp8): P=[IPC] S=EnvFromSMTP/HdrFromSMTP R=EnvToSMTP/EnvToSMTP
                    M=0 U=0:0 F=8DFMXmu L=990 E=\r\n T=DNS/RFC822/SMTP r=100
                    A=TCP $h
mailer 7 (dsmtp): P=[IPC] S=EnvFromSMTP/HdrFromSMTP R=EnvToSMTP/EnvToSMTP
                    M=0 U=0:0 F=%DFMXamu L=990 E=\r\n T=DNS/RFC822/SMTP
                    r=100 A=TCP $h
  mailer 8 (relay): P=[IPC] S=EnvFromSMTP/HdrFromSMTP R=MasqSMTP/MasqSMTP
                    M=0 U=0:0 F=8DFMXamu L=2040 E=\r\n T=DNS/RFC822/SMTP
                    r=100 A=TCP $h

The output shows that all of the SMTP mailers are configured, and so are the prog and local mailers. An examination of the P parameter in the Mlocal line also shows that procmail is being used as the local mailer, which verifies the effect of the local_ procmail feature. Additionally, the P parameter shows that the path to this program matches the one configured by the PROCMAIL_MAILER_PATH define.

sendmail can also be tested by using the -bv command-line option. The -bv option processes an address through sendmail and displays the mail delivery triple for that address. For example:

  # sendmail -bv tyler@example.com
  tyler@example.com... deliverable: mailer esmtp, host example.com, user

This example clearly shows the mailer, host, and user address of the mail delivery triple. In this case, the mail will be addressed to tyler@example.com, sent to the host example.com for delivery, and sent to that host using the esmtp mailer.

When a -bv test is run with an address that is directly delivered by the local host, it has the added benefit of applying aliasing to that address and of verifying if the address is deliverable. Here are some examples:

  # sendmail -bv craig
craig... deliverable: mailer local, user craig
  # sendmail -bv fred
fred... User unknown
  # sendmail -bv admin
anna@crab.wrotethebook.com... deliverable: mailer esmtp, host crab.wrotethebook.com.,
  user anna@crab.wrotethebook.com  
... deliverable: mailer esmtp, host rodent.wrotethebook.
  com., user andy@rodent.wrotethebook.com 
... deliverable: mailer esmtp, host rodent.wrotethebook.
  com., user jane@rodent.wrotethebook.com

The first test shows that craig is a local username deliverable through the local mailer. The second test shows that fred is not a valid local username. The final test shows that admin is expanded by aliasing into three addresses that are forwarded via the esmtp mailer to remote systems for delivery. There are other commands, such as praliases, which allow you to examine the aliases file, but sendmail -bv is the best for seeing exactly how aliasing affects a local delivery address.

Both the -bt and -bv arguments show how the local copy of sendmail handles mail. To examine the interaction with a remote system, sendmail can be used to deliver mail with the verbose (-v) option set. For example:

  $ sendmail -v craig@wrotethebook.com < test.msg 
... Connecting to chef.wrotethebook.com. via esmtp...
  220 chef.wrotethebook.com ESMTP Sendmail 8.12.4/8.12.4; Sat, 2 Aug 2003 16:57:35 -
  >>> EHLO rodent.wrotethebook.com
  250-chef.wrotethebook.com Hello rodent.wrotethebook.com [], pleased to
  meet you
  250 HELP
  >>> MAIL From:<craig@rodent.wrotethebook.com> SIZE=26
  250 2.1.0 craig@rodent.wrotethebook.com>... Sender ok 
>> RCPT To:craig@wrotethebook.com
  550 5.7.1 <craig@wrotethebook.com>... Relaying denied
  >>> RSET
  250 2.0.0 Reset state
  /home/craig/dead.letter... Saved message in /home/craig/dead.letter
  Closing connection to chef.wrotethebook.com.
  >>> QUIT
  221 2.0.0 chef.wrotethebook.com closing connection

Testing sendmail with the -v argument is useful when you want to see the entire protocol interaction. Notice, however, that in the test above there is a “Relaying denied” error message in the line that begins with the code 550. If the real point of this test was to check the recipient address against the remote host, you might not want to see the entire protocol interaction. In that case, using telnet to connect to the SMTP port of the remote system might be a better test tool. For example:

  $ telnet chef.wrotethebook.com smtp
  Connected to chef.wrotethebook.com.
  Escape character is '^]'.
  220 chef.wrotethebook.com ESMTP Sendmail 8.12.9/8.12.9; Sat, 2 Aug 2003 16:57:35 –
HELO rodent.wrotethebook.com
250-chef.wrotethebook.com Hello rodent.wrotethebook.com [], pleased to
  meet you
MAIL From:craig@rodent.wrotethebook.com
  250 2.1.0 <craig@rodent.wrotethebook.com>... Sender ok
RCPT To:craig@wrotethebook.com
  550 5.7.1 <craig@wrotethebook.com>... Relaying denied
221 2.0.0 chef.wrotethebook.com closing connection  
  Connection closed by foreign host.

Using telnet, you can go directly to the specific protocol interaction that you wish to test.

It is important to test sendmail thoroughly before deploying a new configuration. In this book, we use all of the test methods described here.

See Also

The sendmail book covers the -bt option in Chapter 8, the -bv option in section 15.7.15, and the -v option in section 15.7.45.

>>> More Site Administration Articles          >>> More By O'Reilly Media

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Coding: Not Just for Developers
- To Support or Not Support IE?
- Administration: Networking OSX and Win 7
- DotNetNuke Gets Social
- Integrating MailChimp with Joomla: Creating ...
- Integrating MailChimp with Joomla: List Mana...
- Integrating MailChimp with Joomla: Building ...
- Integrating MailChimp with Joomla
- More Top WordPress Plugins for Social Media
- Optimizing Security: SSH Public Key Authenti...
- Patches and Rejects in Software Configuratio...
- Configuring a CVS Server
- Managing Code and Teams for Cross-Platform S...
- Software Configuration Management
- Back Up a Joomla Site with Akeeba Backup

Developer Shed Affiliates


Dev Shed Tutorial Topics: