Sendmail Filter or Milter

To filter email messages before they are delivered by sendmail (to remove viruses, etc.), start up the mail filter along with sendmail. The mail filter must be listening on the same port as sendmail milter is configured to use.

/etc/rc.d/init.d/sendmail:

Add the following lines at the appropriate spots:

     # Start the mail filter
     echo -n $"Starting sendmailfilter: "
     /usr/sbin/sendmailfilter -h -p inet:2526@localhost >/dev/nul 2>&1 &
     FILTVAL=$?
     [ $FILTVAL -eq 0 ] && success "sendmailfilter startup" \
         || failure "sendmailfilter startup"
     echo
          .
          .
          .
     echo -n $"Shutting down sendmailfilter: "
     killproc sendmailfilter
     echo

Compile sendmail with the -DMILTER set. If it was already compiled without it, add the following line to sendmail/devtools/Site/site.config.m4:

     APPENDDEF(`conf_sendmail_ENVDEF', `-DMILTER')dnl

Then, delete the entire sendmail directory named for your operating system. For example: sendmail/obj.Linux.2.2.16-22.i586/sendmail and rebuild using "sh Build". Don't forget to install the new sendmail by issuing a "sh Build install" from the sendmail directory.

Switch to the libmilter directory and build "libmilter.a" (use "sh Build"). This is required before the sendmail filter can be built.

Configure the makefile to build the sendmail filter:

     ./configure --with-sendmail=/sendmail/source/dir

Compile and link the sendmail filter by typing "make".

Note that the sendmail guys have messed up the definition of "bool" in the milter header files on some of the later versions of sendmail. The definition in the mfapi.h file in the milter include directory collides with the definition in the gen.h file in the sendmail directory. The solution is to edit the Makefile and add "-DSM_CONF_STDBOOL_H" to the compile line:

     gcc -c $< $(CFLAGS) -pthread -O2 -DSM_CONF_STDBOOL_H -DNEWDB ...

When it compiles successfully, become root and install the filter:

     su
     make install

Hack the mc file for "sendmail.cf" and add the following milter lines (we add them near the end of the "sendmail.cf" file, just before the mailer definitions):

     define(`FFRMILTER', `1')dnl
     INPUT_MAIL_FILTER(`filter1',`S=inet:2526@localhost, F=R, \
                       T=S:10s;R:60s;E:5m')dnl
     define(`confINPUT_MAIL_FILTERS',`filter1')dnl

Rebuild and install the sendmail.cf file:

     /usr/bin/m4 sendmail.mc >sendmail.cf

/etc/logrotate.d/sendmailfilter:

If the sendmail filter writes logfiles, you should add a config file to rotate them, to the logrotate config directory /etc/logrotate.d, before the logfiles fill up the all of the available disk space:

     /var/log/sendmailfilter {
         missingok
         notifempty
     }