LMTP Configuration of the Procmail LDA in FreeBSD Sendmail

By Weldon Whipple <weldon@whipple.org>

1. Introduction: Definitions

Local Mail Transfer Protocol. A subset of SMTP (Simple Mail Transfer Protocol--the standard protocol used by e-mail servers to communicate with each other.) Sendmail can use LMTP to communicate with the Local Delivery Agent.
LMTP is beneficial when a single incoming e-mail ("envelope") is to be delivered to multiple local recipients. Without LMTP, sendmail just calls the LDA, passing the list of recipients. If the message can't be delivered to one of the recipients for some temporary reason (mailbox full, etc.), the LDA reports to sendmail that the delivery failed (for everybody). If the message is queued and delivery is re-tried later, some recipients might receive the message twice. With LMTP, the status of each recipient's delivery attempt is reported back to sendmail, which now knows exactly who received (or didn't) the message.
LMTP is described in RFC 2033.
A popular program used in the delivery of e-mail. Well-known for its ability to filter spam, procmail can also be configured as sendmail's local delivery agent (replacing mail.local on FreeBSD and other platforms), enabling server-wide filtering--if desired.
Local Delivery Agent. The program that sendmail uses to deliver e-mail on the local server. Delivery generally consists of storing e-mail in the recipients' mailboxes.

2. Configuration

  1. Install procmail from ports, if it isn't already installed. (Type something like "which procmail" to see if it is already installed.)

    To install from ports:

    % su
    # cd /usr/ports/mail/procmail
    # make

    When prompted for test directories, press control-C to cancel the make. We need to edit a header to uncomment a line and enable LMTP:

    # cd work/procmail-3.22/

    Edit config.h. Search for the commented-out line that defines LMTP:

    /*#define LMTP

    Remove the leading slash and asterisk (and matching asterisk and slash) and save the file. Then return to the original procmail directory and resume the build:

    # cd ../..
    # make
    # make install
  2. The above installation places a file named local_procmail_lmtp.m4 in the directory /usr/local/share/examples/procmail. Copy that file to the directory /usr/share/sendmail/cf/feature/
    The directory /usr/share/sendmail/cf/feature/ should already contain a file named local_procmail.m4, shipped with sendmail. That file lets you use procmail as the local delivery agent, but without LMTP.
  3. Modify your sendmail mc (macro configuration) file to use the local_procmail_lmtp feature. Add a line that reads:

    to the mc file, before any lines that begin "MAILER ...".

    In the FEATURE line, the first quote is a "back" quote; the second is an apostrophe.
    If this is the first time you have modified the sendmail.cf on this FreeBSD server, create a "working" mc file by issuing the following command (as root):

    cd /etc/mail; make
    The make command will copy freebsd.mc to <hostname>.mc, where <hostname> is your server's host name. (On my mail.whipple.org mail server, the resulting mc file is named mail.whipple.org.mc) Edit the newly created <hostname>.mc and add the local_procmail_lmtp feature as instructed above.
  4. Build a new sendmail.cf file and restart sendmail:
    # make
    # make install
    # make restart
    The first make generates <hostname>.cf from <hostname>.mc; the second copies <hostname>.cf to sendmail.cf; the third restarts the sendmail daemons.

Verify that sendmail still works correctly by sending and receiving some test e-mail and inspecting /var/log/maillog.