Next Previous Contents

2. Installation and Configuration

This documentation is based on the Linux distribution I used (Red Hat 9 with Postfix), and although it should work on most any Linux distribution, you may need to defiate from the exact instructions to get it working on your particular flavour of Linux.

2.1 Installing alterMIME

alterMIME can be downloaded from http://www.pldaniels.com/altermime/. The version I used was 0.3.1.

Once downloaded, you need to unpack the tarball, change into the new directory and run

make

After building the altermime executable, install it as follows

cp altermime /usr/bin/
chown root.root /usr/bin/altermime
chmod 755 /usr/bin/altermime

2.2 Adding a Non-Privileged User To Run alterMIME

Unless you have already done this to run other filters in Postfix, the next step is to add a user account to the system that Potfix will use to run the alterMIME filter

useradd -r -c "Postfix Filters" -d /var/spool/filter filter

Once you have created this account you need to create the account's home directory

mkdir /var/spool/filter
chown filter.filter /var/spool/filter
chmod 750 /var/spool/filter

2.3 Creating The Script To Run alterMIME

You now need to create the following script, changing whatever you need to personalize it

/etc/postfix/disclaimer


#!/bin/sh 
# Localize these. 
INSPECT_DIR=/var/spool/filter
SENDMAIL=/usr/sbin/sendmail

# Exit codes from <sysexits.h> 
EX_TEMPFAIL=75 
EX_UNAVAILABLE=69 

# Clean up when done or when aborting. 
trap "rm -f in.$$" 0 1 2 3 15 

# Start processing. 
cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit 
$EX_TEMPFAIL; }

cat >in.$$ || { echo Cannot save mail to file; exit $EX_TEMPFAIL; } 

/usr/bin/altermime --input=in.$$ \
                   --disclaimer=/etc/postfix/disclaimer.txt \
                   --disclaimer-html=/etc/postfix/disclaimer.txt \
                   --xheader="X-Copyrighted-Material: Please visit http://www.company.com/privacy.htm" || \
                     { echo Message content rejected; exit $EX_UNAVAILABLE; } 

$SENDMAIL -oi "$@" <in.$$ 
 
exit $?

Once you have created this script, set the permissions to allow it to be executed by the filter user

chgrp filter /etc/postfix/disclaimer
chmod 750 /etc/postfix/disclaimer

2.4 Creating The Disclaimer Files

You need to create the disclaimer text file that was specified in the disclaimer.sh file

/etc/postfix/disclaimer.txt

The content of this file is very much dependent on your requirements, but examples can be found at http://www.emaildisclaimers.com.

In my situation, I have used the same file for both the --disclaimer and --disclaimer-html files. I tried to use the --htmltoo parameter to tell alterMIME to use the same file for both, but this did not seem to work correctly.

2.5 Postfix Configuration

Finally, you need to configure Postfix to run the filter. In my case, I only wanted outgoing messages to be modified, so I explicitly configured Postfix to listen on different network interfaces, but to only run the filter on the one.

To achieve this, you need to modify the smtp service in etc/postfix/master.cf/ to be as follows


<incoming ip>:smtp        inet        n        -        y        -        -        smtpd
<outgoing ip>:smtp        inet        n        -        y        -        -        smtpd
    -o content_filter=dfilt:

replacing <incoming ip> and <outgoing ip> with the IP addresses of the different network interfaces. In practice, these IP addresses could be bound to the same network controller.

Now you need to add the following new service to the same file


dfilt     unix    -       n       n       -       -       pipe
    flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}

NOTE: You need to ensure that local processes are still able to send mail. The simplest case way is to include a line like the one below in etc/postfix/master.cf/ (Thank you to Ian Clancy for pointing out this omisson).


127.0.0.1:smtp        inet        n        -        y        -        -        smtpd

Once you have done this, restart Postfix and send through some test messages whilst watching the mail log. If everything goes through fine, without any errors, you can pat yourself on the back and go get a cup of coffee.


Next Previous Contents