Administration
  Home arrow Administration arrow Page 12 - Getting Started with Sendmail
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ADMINISTRATION

Getting Started with Sendmail
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 17
    2005-07-07

    Table of Contents:
  • Getting Started with Sendmail
  • The cf directory structure
  • The cf/m4 directory
  • 1.1 Downloading the Latest Release
  • 1.2 Installing sendmail
  • 1.3 Compiling sendmail to Use LDAP
  • 1.4 Adding the regex Map Type to sendmail
  • 1.5 Compiling sendmail with SASL Support
  • 1.6 Compiling sendmail with STARTTLS Support
  • 1.7 Compiling in STARTTLS File Paths
  • 1.8 Building a sendmail Configuration
  • 1.9 Testing a New Configuration
  • 1.10 Logging sendmail

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Getting Started with Sendmail - 1.9 Testing a New Configuration
    (Page 12 of 13 )

    Problem

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

    Solution

    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.

    Table 1-2. sendmail test mode commands

    CommandUsage
    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.
    /canonhostnameCanonifyhostname.
    /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
    /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 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 Administration Articles
    More By O'Reilly Media


       · quite a good article!
       · Really Nice Article
     

    Buy this book now. This article was excerpted from chapter one of The Sendmail Cookbook, written by Craig Hunt (O'Reilly Media, 2004; ISBN: 0596004710). Check it out at your favorite bookstore. Buy this book now.

       

    ADMINISTRATION ARTICLES

    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization
    - Advanced Concepts on Dealing with Files and ...
    - Dealing with Files and Filesystems
    - More Hacks for the User Environment in BSD
    - Personalizing the User Environment in BSD
    - Customizing the User Environment in BSD

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway