ProblemYou need to test the sendmail configuration before it is deployed. SolutionUse the sendmail command-line options -bt , -bv , and -v . DiscussionAt 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
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.cf M commands: # sendmail -bt -C/usr/local/src/sendmail-8.12.9/cf/cf/sendmail.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 > /quit 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 tyler@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 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 andy@rodent.wrotethebook.com... deliverable: mailer esmtp, host rodent.wrotethebook. com., user andy@rodent.wrotethebook.com jane@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 craig@wrotethebook.com... 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 - 0400 >>> EHLO rodent.wrotethebook.com 250-chef.wrotethebook.com Hello rodent.wrotethebook.com [192.168.0.3], pleased to meet you 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-EXPN 250-VERB 250-8BITMIME 250-SIZE 250-DSN 250-ETRN 250-DELIVERBY 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 Trying 192.168.0.8... 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 - 0400 HELO rodent.wrotethebook.com 250-chef.wrotethebook.com Hello rodent.wrotethebook.com [192.168.0.3], 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 QUIT 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 AlsoThe 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. |