Tip: Add Disclaimer To Only Outgoing Email Using Altermime

On our mail server at work, we added a disclaimer to all outgoing emails using Altermime. This has been working fine for a few months now. There was just one thing that annoyed me about it, it added to all outgoing emails, including internal mail between users.

So I went about trying to find a solution and eventually found out how to do it so thought I’d share it here and also keep it as a reference to me as it took me ages to find it 😛

  1. # wget http://www.pldaniels.com/altermime/altermime-0.2.2.tar.gz
    # tar -xzvf altermime-0.2.2.tar.gz
    # cd altermime-0.2.2
    # make

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

  2. # 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
  3. # Creating The Script To Run alterMIME

    # vi /etc/postfix/disclaimer

    # Localize these.
    #Exit codes from
    RECIP=`echo $* | awk '{print $NF}'| tr [A-Z] [a-z]`
    SENDER=`echo $* | awk '{print $2}'| tr [A-Z] [a-z]`
    RECIP_DOMAIN=`echo $RECIP | awk -F"@" '{print $2}'`
    SEND_DOMAIN=`echo $SENDER | awk -F"@" '{print $2}'`
    # 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; }
    if [ $RECIP_DOMAIN == $SEND_DOMAIN ]; then
    /usr/bin/altermime --input=in.$$ 
    --disclaimer-html=$DISCLAIMER || 
    { echo Message content rejected; exit $EX_UNAVAILABLE; }
    $SENDMAIL "$@" 

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

    /etc/postfix/empty_disclaimer.txt is the disclaimer which will get used for internal email, ie when the sending domain is the same as the receiving domain, in my case I made it a blank file.
    /etc/postfix/disclaimer.txt is the disclaimer which gets added to all other emails, in that we have some stuff saying it may be copyrighted or something, can't remember now.

  4. # Creating The Disclaimer Files

    # vi /etc/postfix/disclaimer.txt
    # vi /etc/postfix/empty_disclaimer.txt

  5. # Postfix Configuration

    Edit master.cf :

    # vi /etc/postfix/master.cf inet n - y - - smtpd
    smtp inet n - y - - smtpd
    -o content_filter=dfilt:
    dfilt unix - n n - - pipe
    flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} — ${recipient}

  6. # Restart Postfix

    # postfix reload