Sendmail (version 8.10.1 or above), including the "libmilter" library, must
be built before the filter program can be compiled. Information on building
Sendmail and libmilter, so that the Mail Filter API is available, is
distributed with Sendmail in the
file "sendmail-8.1N.N/libmilter/README". Please
read the relevant parts of that file first.
Installing the Filter
- Download the "tar" file or the "gzipped tar" file appropriate to the
version of Sendmail that you are running. Save the file in a convenient
directory outside the Sendmail source directory tree.
- Unzip and uncompress the tar archive, e.g.:
% gunzip rays-filter-1.NN.tar.gz
This should create a subdirectory
called rays-filter-1.NN which contains the following
files. The ones marked with "*" are required to produce a
% tar xvf rays-filter-1.NN.tar
|Shell scripts *
|C source files *
|Configuration files *
|Licence & Copyright
- Make the following changes to the files as required:
This is just a handy script to save having to type out the whole
command line when you want to compile rays-filter.c.
Edit the following values as required:-
SRCDIR should equal the absolute path to your sendmail
source directory, e.g.
OBJDIR should be the location, relative to SRCDIR, of
the platform-specific object directory which is created when you build
Depending on your operating system and/or C compiler, you may also
have to modify the compiler command (e.g. gcc instead of cc)
and/or some of the compiler options. See the
file libmilter/README (distributed with Sendmail) for more
The WORK_DIR variable specifies the directory that you
wish the filter to use as its working directory. This directory
must be created before the filter program is started. It will
contain the log files produced by the scripts and utilities, and
the rejects subdirectory, where the rejected messages
will be saved. E.g.:
The SOCKET variable specifies the socket that you want
the mail filter to create and use to communicate with Sendmail.
The socket can be a local file or an internet port. The way
that sockets are specified varies between different
versions of Sendmail. Refer to the
file libmilter/README, distributed with Sendmail, for
the various socket options. (See also the table of
known bugs). If a
local file socket is specified,the user who will run the filter
must have read, write and execute access to the directory where
it will reside. E.g.:
These configuration files specify the criteria by which the filter will
accept or reject messages. These files can be edited at any time, even
while the filter is running. See the
Configuration Page for details.
The text part of the
SMTP reply can be specified
in this file if you don't want to use the default message. Other
parameters can also be changed. See the comments in the file for details.
- Compile and link the program using the build script (or the
command line given in the libmilter/README file referred to above):
% ./build rays-filter
If successful, this will produce a binary file, rays-filter.
- Copy the following files into /usr/local/bin:-
If you wish to use the utilities, then also
copy the following files:-
Ensure that the user who will run the filter has read and execute rights to
these files. (The filter does not have to be run by root - however, see the
remarks about sockets in the table of
- Create the directory /usr/local/etc/mail-filter, and copy the
following files into it:-
Ensure that the user who will run the filter has read and write privileges to
- Create the filter's working directory, as specified
in mail-filter.conf. Within this directory, create a
sub-directory called rejects. If you intend to use the
Analysis Utility, then
also create a subdirectory called analysis, i.e.
% mkdir WORK_DIR
where WORK_DIR is the value of the WORK_DIR variable
specified in mail-filter.conf. Ensure that the user who will run the
filter has read, write and execute privileges in all of these directories.
% mkdir WORK_DIR/rejects
% mkdir WORK_DIR/analysis
- At this point the filter can be started and stopped, as described in the
Operation Page to make sure it will run and
make entries in its log file, mail-filter.log, and the system log
file. However, it will not actually filter any messages until references
to it are added to the Sendmail configuration file, sendmail.cf.
- Insert the following lines into sendmail.cf,
after the definitions of mail delivery agents (lines beginning
Xrays-filter, S=local:/users/mf-user/mail-filter/mf-socket, F=R, T=S:60s;R:60s;E:5m
Note that the socket specification, "S=...", must match
the SOCKET specified in mail-filter.conf. Please see the
file distributed with Sendmail, libmilter/README, for information
about the "F=..." and "T=..." parameters.
- Shut down sendmail.
- Start the filter:
% /usr/local/bin/mail-filter start
- Re-start sendmail.
- Check the system log files to verify that Sendmail and the filter are
both functioning correctly.
Ray's Mail Filter Home Page
Running the Filter
08 March 2001