cc -I/path/to/include -I/path/to/sendmail -c myfile.cand your linking command line will look something like
cc -o myfilter [object-files] -L[library-location] -lmilter -pthread
Next, you must add the desired filters to your sendmail configuration
(.mc) file.
Mail filters have three equates:
The required S=
equate specifies the socket where
sendmail should look for the filter; the optional F=
and
T=
equates specify flags and timeouts, respectively.
All equates names, equate field names, and flag values are case sensitive.
The current flags (F=
) are:
Flag | Meaning |
---|---|
R | Reject connection if filter unavailable |
T | Temporary fail connection if filter unavailable |
There are four fields inside of the T=
equate: C, S, R, and E.
Note the separator between each is a ";" (semicolon), as ","
(comma) already separates equates.
The value of each field is a decimal number followed by a single letter
designating the units ("s" for seconds, "m" for minutes).
The fields have the following meanings:
Flag | Meaning |
---|---|
C | Timeout for connecting to a filter. If set to 0, the
system's connect(2) timeout will be used.
Default: 5m |
S | Timeout for sending information from the MTA to a filter. Default: 10s |
R | Timeout for reading reply from the filter. Default: 10s |
E | Overall timeout between sending end-of-message to filter and waiting for the final acknowledgment. Default: 5m |
The following sendmail.mc example specifies three filters. The first two rendezvous on Unix-domain sockets in the /var/run directory; the third uses an IP socket on port 999.
INPUT_MAIL_FILTER(`filter1', `S=unix:/var/run/f1.sock, F=R') INPUT_MAIL_FILTER(`filter2', `S=unix:/var/run/f2.sock, F=T, T=S:1s;R:1s;E:5m') INPUT_MAIL_FILTER(`filter3', `S=inet:999@localhost, T=C:2m') define(`confINPUT_MAIL_FILTERS', `filter2,filter1,filter3')By default, the filters would be run in the order declared, i.e. "filter1, filter2, filter3"; however, since
m4 ../m4/cf.m4 myconfig.mc > myconfig.cf
confINPUT_MAIL_FILTERS
is defined, the filters will be
run "filter2, filter1, filter3".
Also note that a filter can be defined
without adding it to the input filter list by using
MAIL_FILTER() instead of INPUT_MAIL_FILTER().
The above macros will result in the following lines being added to your .cf file:
Xfilter1, S=unix:/var/run/f1.sock, F=R Xfilter2, S=unix:/var/run/f2.sock, F=T, T=S:1s;R:1s;E:5m Xfilter3, S=inet:999@localhost, T=C:2m O InputMailFilters=filter2,filter1,filter3
Finally, the sendmail macros accessible via smfi_getsymval can be configured by defining the following m4 variables (or cf options):
In .mc file | In .cf file | Default Value |
---|---|---|
confMILTER_MACROS_CONNECT | Milter.macros.connect | j, _, {daemon_name}, {if_name}, {if_addr} |
confMILTER_MACROS_HELO | Milter.macros.helo | {tls_version}, {cipher}, {cipher_bits}, {cert_subject},
{cert_issuer} |
confMILTER_MACROS_ENVFROM | Milter.macros.envfrom | i, {auth_type}, {auth_authen}, {auth_ssf}, {auth_author},
{mail_mailer}, {mail_host}, {mail_addr} |
confMILTER_MACROS_ENVRCPT | Milter.macros.envrcpt | {rcpt_mailer}, {rcpt_host}, {rcpt_addr} |