How To Automatically Add A Disclaimer To Outgoing Emails With alterMIME (Postfix On Debian Squeeze)

This tutorial shows how to install and use alterMIME. alterMIME is a tool that can automatically add a disclaimer to emails. In this article I will explain how to install it as a Postfix filter on Debian Squeeze.


1 Preliminary Note

I'm assuming that Postfix is already installed and fully functional - I will not explain how to set up Postfix and configure email accounts in this tutorial.


2 Installing alterMIME

alterMIME can be installed as follows:

apt-get install altermime

Next we create the user filter with the home directory /var/spool/filter filter - alterMIME will be run as that user:

useradd -r -c "Postfix Filters" -d /var/spool/filter filter
mkdir /var/spool/filter
chown filter:filter /var/spool/filter
chmod 750 /var/spool/filter

Afterwards we create the script /etc/postfix/disclaimer which executes alterMIME. Debian's alterMIME package comes with a sample script that we can simply copy to /etc/postfix/disclaimer:

cp /usr/share/doc/altermime/examples/ /etc/postfix/disclaimer
chgrp filter /etc/postfix/disclaimer
chmod 750 /etc/postfix/disclaimer

Now the problem with this script is that it doesn't distinguish between incoming and outgoing emails - it simply adds a disclaimer to all mails. Typically you want disclaimers only for outgoing emails, and even then not for all sender addresses. Therefore I've modified the /etc/postfix/disclaimer script a little bit - we'll come to that in a minute.

Right now, we create the file /etc/postfix/disclaimer_addresses which holds all sender email addresses (one per line) for which alterMIME should add a disclaimer:

vi /etc/postfix/disclaimer_addresses
[email protected]
[email protected]
[email protected]

Now we open /etc/postfix/disclaimer and modify it as follows (I have marked the parts that I've changed):

vi /etc/postfix/disclaimer
# Localize these.

####### Changed From Original Script #######
####### Changed From Original Script END #######

# Exit codes from <sysexits.h>

# 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

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

####### Changed From Original Script #######
# obtain From address
from_address=`grep -m 1 "From:" in.$$ | cut -d "<" -f 2 | cut -d ">" -f 1`

if [ `grep -wi ^${from_address}$ ${DISCLAIMER_ADDRESSES}` ]; then
  /usr/bin/altermime --input=in.$$ \
                   --disclaimer=/etc/postfix/disclaimer.txt \
                   --disclaimer-html=/etc/postfix/disclaimer.txt \
                   --xheader="X-Copyrighted-Material: Please visit" || \
                    { echo Message content rejected; exit $EX_UNAVAILABLE; }
####### Changed From Original Script END #######

$SENDMAIL "[email protected]" <in.$$

exit $?

Next we need the text file /etc/postfix/disclaimer.txt which holds our disclaimer text. Debian's alterMIME package comes with a sample text that we can use for now (of course, you can modify it if you like):

cp /usr/share/doc/altermime/examples/disclaimer.txt /etc/postfix/disclaimer.txt

Finally we have to tell Postfix that it should use the /etc/postfix/disclaimer script to add disclaimers to outgoing emails. Open /etc/postfix/ and add -o content_filter=dfilt: to the smtp line:

vi /etc/postfix/
# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
# Do not forget to execute "postfix reload" after editing this file.
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
smtp      inet  n       -       -       -       -       smtpd
   -o content_filter=dfilt:

At the end of the same file, add the following two lines:

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

Restart Postfix afterwards:

/etc/init.d/postfix restart

That's it! Now a disclaimer should be added to outgoing emails sent from the addresses listed in /etc/postfix/disclaimer_addresses.


Share this page:

6 Comment(s)

Add comment

Please register in our forum first to comment.


By: mbsouth

Would be of interest to know how to do this per domain and with a database that the domain admins could handle the disclaimer.

By: diego soto


from_address=`grep -m 1 "^From: " in.$$ | cut -d "<" -f 2 | cut -d ">" -f 1`
now it works good

By: HerBi

For those who have truncated mails, try the "-i" option in the script for sendmail... '$SENDMAIL -i "[email protected]" <in.$$'

By: Jeremy Smith

I found actually when using DKIM in my instance (annoying as it was when trying to get this to work) it kept finding the first From: which would be within the signature so it'd never find the From: with the email address from the sender missing out the disclaimer entirely, this is what I have worked out what works for me (when sending originals out, so far anyway... though for some forwarded ones it doesn't at least for some strange reason), so had to change the from_address variable to:

from_address=`grep -m3 "From:" in.$$ | tail -n1 | cut -d "<" -f 2 | cut -d ">" -f 1`

By: Stefan Bauer

I´m having some troubles using this HowTo.

If I´m using Altermime without the modifications regarding the specified disclaimer_addresses it is working fine (just disabled the if-statement). The disclaimer is added to each outgoing email.

If I use the if-satement, I have differen ouput in the mail.log-file, but no disclaimer is added:

Apr  3 09:22:37 zulu1234 postfix/pipe[5999]: 894449F4B1B: to=<[email protected]>, relay=dfilt, delay=17, delays=17/0.01/0/0.16, dsn=2.0.0, status=sent (delivered via dfilt service)Apr  3 09:25:17 zulu1234 postfix/pipe[6585]: 79D639F4B1B: to=<[email protected]>, relay=dfilt, delay=7.1, delays=7/0.01/0/0.08, dsn=2.0.0, status=sent (delivered via dfilt service (grep: [email protected]: No such file or directory))

The first Email (894449F4B1B) is an outgoing Mail that should contain the disclaimer, but does not.The second Email (79D639F4B1B) is an outgoing Mail that should NOT contain the disclaimer (and does not).

Any tip what causes that issue and how to solve?



By: Ansar

Hellow: sir, I tried step by step all done without error, but no luck, SMTP stop telneting itself....? how to rectify the actual issue when configuring disclaimer in Ubuntu 18 postfix with ispconfig3