You need to test the sendmail configuration before it is deployed.
Use the sendmail command-line options -bt, -bv, and -v.Discussion
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.
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
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 email@example.com
This example clearly shows the mailer, host, and user address of the mail delivery triple. In this case, the mail will be addressed to firstname.lastname@example.org, 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
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 email@example.com < test.msg
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
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.
blog comments powered by Disqus