Sendmail Configuration

There are several parts to the sendmail configuration that must be used.

Sendmail.mc

Below is a sendmail.mc file with notes:

Example 4-15. sendmail.mc file

    divert(-1)dnl
    #
    #  This file contains definitions for mail.mydomain.com
    #
    divert(0)dnl
    include(`/usr/lib/sendmail-cf/m4/cf.m4')
    VERSIONID(`@(#)mailserver.mc     1.0 (mydomain.com) 5/1/97')
    OSTYPE(linux)
    DOMAIN(generic)
    dnl Note: The following feature is an aliases file that allows
    dnl sendmail to recognize mail coming in to several host names 
    dnl for this machine
    FEATURE(`use_cw_file')
    define(`confCW_FILE',`/etc/sendmail.cw')
    FEATURE(nouucp)
    dnl Note: The virtusertable feature allows you to create an aliases
    dnl file for users that only have cyrus accounts or to forward mail to
    dnl another address not handled by this server. The access_db feature
    dnl allows you to control which hosts and addresses may relay mail
    dnl using this machine. For more information on this and other
    dnl anti-spam features, see     http://www.sendmail.org/m4/anti-spam.html.
    FEATURE(`virtusertable', `hash /etc/mail/virtusertable')
    FEATURE(`access_db', `hash /etc/mail/access')
    dnl Note: This allows all relayed messages to appear as if they
    dnl are coming from user@mydomain.com instead of user@host.mydomain.com
    MASQUERADE_AS(mydomain.com)
    dnl Note: This is probably one of the most important entries,
    dnl LUSER_RELAY tells sendmail to send mail for users that do not have
    dnl local system accounts on this machine to the cyrus mailer on
    dnl localhost. Without this entry, all mail addressed to cyrus users
    dnl would bounce as user unknown.
    define(`LUSER_RELAY', `cyrus:localhost')
    dnl Note: rbl uses the Realtime Blackhole List database to keep
    dnl known spammers from accessing your mail server, for more
    dnl information, please see http://www.sendmail.org/m4/anti-spam.html.
    FEATURE(rbl)
    dnl Note: This feature allows users mail to be forwarded with a
    dnl .forward file in the users home directory, this is only for users
    dnl with system accounts, for cyrus only users, use the virtusertable
    dnl feature.
    FEATURE(`redirect')
    dnl Note: This uses procmail instead of the old mail executable for
    dnl local delivery.
    FEATURE(`local_procmail')
    dnl Note: These are the mailer definitions, this allows sendmail to
    dnl use smtp to deliver outgoing mail, cyrus for imap and pop3 users
    dnl and procmail for local system account delivery (root).
    MAILER(smtp)
    MAILER(procmail)
    MAILER(cyrus)

You may need to add or modify features for your particular needs. When you are done generate the sendmail.cf file by typing the following command: m4 sendmail.mc > sendmail.cf

Both of these files should reside in /etc.

Directing system account mail to the cyrus mailer

On my mail server I have a system account setup for myself which has the same username that I use for my mail address. Sendmail was delivering my mail to the local account rather than the cyrus account. I did not want to use cyrus for all my system accounts, especially since my cyrus imap server was using pam_ldap to authenticate users. In my /etc/sendmail.cf file that I output using the /etc/sendmail.mc file in the above section, I added the following under the Class definition section:

Example 4-16. Sendmail Class Definitions

    # class C: names that should be sent to cyrus
    CC <First User>

In the Parse1 section of Ruleset 0 I added the following 2 lines to the #short circuit local delivery so forwarding works sub-section:

Example 4-17. Short Circuiting Delivery (Original)

    R$=C < @ $=w . >        $#cyrus $: @ $1         special <First User> rule

    R$=C < @ $=w . >        $#cyrus $: $1           special <First User> rule

So now my #short circuit local delivery so forwarding works sub-section of the Parse1 section looked like the following:

Example 4-18. Short Circuiting Delivery (New)

    # short circuit local delivery so forwarded email works

    R$=C < @ $=w . >        $#cyrus $: @ $1         special <First User>rule

    R$=C < @ $=w . >        $#cyrus $: $1           special <First User>rule

    R$=L < @ $=w . >        $#local $: @ $1         special local names

    R$+ < @ $=w . >         $#local $: $1           regular local names

I also had to add the following 2 lines to the #handle locally delivered names sub-section of the Parse1 section:

Example 4-19. Handling Locally Delivered Names (Original)

    R$=C @ $=w              $#cyrus $: @ $1                 special <First User>rule

    R$=C                    $#cyrus $: @ $1                 special <First User>rule

So now the #handle locally delivered names sub-section of the Parse1 section looked like the following:

Example 4-20. Handling Locally Delivered Names (New)

    # handle locally delivered names

    R$=C @ $=w              $#cyrus $: @ $1                 special <First User>rule

    R$=C                    $#cyrus $: @ $1                 special <First User>rule

    R$=L                    $#local $: @ $1                 special local names

    R$+                     $#local $: $1                   regular local names

There is a way to add these rules and class to the sendmail.mc file rather than the gory additions to the sendmail.cf file, if you would like to study up on sendmail and send me the lines for the sendmail.mc file, I will gladly replace this section with them. For every user that needs to have mail delivered to cyrus instead of locally, add their user id to the class definition line. This list should be single-space separated. This inelegant method must be administered every time you rebuild the sendmail.cf file from the sendmail.mc file.

Restarting and monitoring sendmail

Every time your /etc/sendmail.cf changes you must restart sendmail to have the changes take effect. Do this by using the sendmail startup script in /etc/rc.d/init.d/ by typing /etc/rc.d/init.d/sendmail restart . You may also check for errors in the sendmail logfile: /var/log/maillog. I usually run tail -f /var/log/maillog when I am testing sendmail configurations and open the log file in an editor only when I am looking for past errors or information.