Pages

Saturday 25 November 2017

Disclaimer in postfix


ADD A DISCLAIMER TO OUTGOING EMAILS VIA alterMIME

1 . install epel repo

[root@server ~]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@server ~]# rpm -Uvh epel-release-6-8.noarch.rpm
[root@server ~]# yum repolist
[root@server ~]# yum install altermime

2. check altermime is install or not

[root@server ~]# al
alias altermime alternatives

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

[root@server ~]# useradd -r -c "Postfix Filters" -d /var/spool/filter filter
[root@server ~]# mkdir /var/spool/filter
[root@server ~]# chown filter:filter /var/spool/filter
[root@server ~]# chmod 750 /var/spool/filter

4. Now create the script /etc/postfix/disclaimer which executes alterMIME.

[root@server ~]# vim /etc/postfix/disclaimer
[root@server ~]# chgrp filter /etc/postfix/disclaimer
[root@server ~]# chmod 750 /etc/postfix/disclaimer
[root@server ~]# cat /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.html \
--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 $?

5. 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:

[root@server ~]# vim /etc/postfix/disclaimer_addresses
[root@server ~]# cat /etc/postfix/disclaimer_addresses
user1@zmailtech.com
user2@zmailtech.com

6. Next we need the text file /etc/postfix/disclaimer.txt which holds our disclaimer text.

[root@server ~]# vim /etc/postfix/disclaimer.txt
[root@server ~]# cat /etc/postfix/disclaimer.txt
This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of “[zmailtech]“.
If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone.
Please contact the sender if you believe you have received this email in error

7. Next we need the html file /etc/postfix/disclaimer.html which holds our disclaimer html.

[root@server ~]# cat /etc/postfix/disclaimer.html
<hr><br>
This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of “[zmailtech]“.
If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone.
Please contact the sender if you believe you have received this email in error.

8. 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:

[root@server ~]# cp /etc/postfix/master.cf /etc/postfix/master.cf.org
[root@server ~]# vim /etc/postfix/master.cf
[root@server ~]# cat /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").
#
# =======================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# =======================================================
#add
smtp inet n - - - - smtpd
-o content_filter=dfilt:
[...]
# add
[...]
dfilt unix - n n - - pipe
flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}

9. restart postfix mail server

[root@server ~]#/etc/init.d/postfix restart

No comments:

Post a Comment