Disclaimer To Outgoing Emails

Adding text automatically to the end of all e-mails sent from the system is one of the most popular application. I’ll tell you how to do this below.
Our system works on Debian as Postfix. The actions are as follows:

  1. We are using “alterMIME” package to add content to end of the mail body. This package comes from the Debian repository.
    For Installation:

# apt-get install altermime

2. Copy the following sample script to “/etc/postfix“ directory.

# cp /usr/share/doc/altermime/examples/postfix_filter.sh /etc/postfix/disclaimer
# chown vmail:vmail /etc/postfix/disclaimer
# chmod 750 /etc/postfix/disclaimer

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

# Exit codes from
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 "$@"

3. Copy the sample content which we want to add to the mail body and do your changes.

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

4. Postfix settings:

# vi /etc/postfix/master.cf

smtp inet n - - - - smtpd
-o content_filter=dfilt:
[...]

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

5. Restart Postfix Service:

# /etc/init.d/postfix restart

If you don’t want to impact all user, you can set relevant users as following.

# vi /etc/postfix/disclaimer_addresses

You should create the file that name is “disclaimer_addresses” and write usernames to the file. Then you must change the script as followings.

#!/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
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 "$@"

DevOps & Software & Architect & Linux Geek — http://baturorkun.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store