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

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2010-09-19 16:44. :: Debian | Postfix

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

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 08/18/2010

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 Lenny.

I do not issue any guarantee that this will work for you!

 

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:

aptitude 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/postfix_filter.sh /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

falko@example.com
joe@example.org
tom@example.net

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

vi /etc/postfix/disclaimer

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

####### Changed From Original Script #######
DISCLAIMER_ADDRESSES=/etc/postfix/disclaimer_addresses
####### Changed From Original Script END #######

# 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; }

####### 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 http://www.company.com/privacy.htm" || \
                    { echo Message content rejected; exit $EX_UNAVAILABLE; }
fi
####### Changed From Original Script END #######

$SENDMAIL "$@" <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/master.cf and add -o content_filter=dfilt: to the smtp line:

vi /etc/postfix/master.cf

#
# 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.

 

3 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Sun, 2011-11-06 23:36.

Hello,

I followed  your post and I made it work but only the disclaimer.txt is added but not the disclaimer.html.

have you an idea about how to add an html disclaimer??

 

Thanks

Submitted by Tales Freitas (not registered) on Thu, 2011-05-05 18:39.

Good Afternoon.

 I need to configure the disclaimer. The config is ok, but the font size is very large and i'd like to reduce the size of the font to 8pt. Is it is possible?

 I'm wainting a reply.

 Thanks.

 Sorry about the englesh.

Submitted by Anonymous (not registered) on Tue, 2010-12-21 16:15.

Current altermime in Debian Lenny adds garbage when Outlook sends in RTF.

You need to get the patch from here: http://r0b0tz.com/?p=19

and remake the Debian packages

Submitted by withanh (not registered) on Mon, 2010-10-04 03:29.

It is over my head how to configure, but it would be cool to integrate this with http://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-debian-lenny, maybe a boolean field in the users table for disclaimer (to send or not).

Thanks for the great how-to's!

 h

Submitted by alinflabs (registered user) on Tue, 2010-10-26 20:30.

I have implemented this on a mail server configured like the one listed by you. The only change that you have to do in order to make it work is :

from_address=`grep -m 1 "From:" in.$$ | cut -d " " -f 2 | cut -d " " -f 1` 

 You have a space on " cut -d "space" '.

It took me an hour of troubleshooting in order to realize why doesn't work " out of the box".

Submitted by guddukhan1987 (registered user) on Fri, 2011-05-20 10:32.

This option is working fine with my mail server.

Thanks for the advice.

 Thanks alot.

 

Guddu Khan

Submitted by David F. Skoll (not registered) on Wed, 2010-09-22 14:04.

Email disclaimers are useless and very likely unenforceable.  Just because you can add them doesn't mean you should.  Google "Stupid email disclaimers".

 

Submitted by withanh (not registered) on Mon, 2010-10-04 03:48.

David,

Disclaimers aren't the only application for this.  I run the mail server for a small business that does most communication through email blasts (aka a mailing list).  The owner of the business wants anyone who has a company email address to have a "disclaimer" at the bottom with instructions on how to join the mailing list.  Very valid in my case, and nothing to do with "disclaimers".

h