How to Block incoming in zimbra user wise

Git server commands

There is no detect way to do block incoming mail from external domain to some Zimbra Users. You can block incoming by domain,email-id for All zimbra Users, but not for few.

So guy here we explained how to block incoming Email from External domain for some user.

first Create a filter rule and Disable filter from admin UI so user can not see filter value.

zmmailbox -z -m [email protected] addFilterRule "Allow internal Domain only" active all address "from" domain not_contains "knowledgelinux.com" discard stop

Now you can not view external Domain Emails But External Sender will not get any bounced back. so create a linux scripts and schedule it ever 10 min. it will look and send back a message to sender with bounced back.

*/10 * * * * /bin/sh /incoming_filter_bounced.sh >/dev/null 2>&1
#/bin/bash
#Written by vikas kushwaha
#if file not exsits create it
>/tmp/list_external_email.txt
DATE=`date +%d%m%y`
if [ ! -f "/tmp/master-"$DATE".log" ]; then touch /tmp/master-"$DATE".log ;fi
Master_log="/tmp/master-"$DATE".log"
if [ ! -f "/tmp/Previous_ckeck_line_no.txt" ]; then touch /tmp/Previous_ckeck_line_no.txt ;fi
Previous_ckeck_line_no=$(cat /tmp/Previous_ckeck_line_no.txt)
#if file blank, then start from 1 number,assign variable
if [ ! -s "/tmp/Previous_ckeck_line_no.txt" ];then Previous_ckeck_line_no=1;fi

Currect_line_no_ofLOG=$(cat /var/log/zimbra.log | wc -l)
echo "Log Line check from $Previous_ckeck_line_no to $Currect_line_no_ofLOG"
echo "">>$Master_log
echo "">>$Master_log
echo "######################################################" >>$Master_log
echo `date` >>$Master_log
echo "Log Line check from $Previous_ckeck_line_no to $Currect_line_no_ofLOG" >>$Master_log

###################################################
for knowledgelinux_id in [email protected] [email protected] [email protected] [email protected] [email protected]
do

#sed -n -e "$Previous_ckeck_line_no,$Currect_line_no_ofLOG p" /var/log/zimbra.log | grep -i "to=<$knowledgelinux_id>" | grep -i "from=<" | cut -d ";" -f2 | cut -d ">" -f1| cut -d "<" -f2 | grep -v "knowledgelinux.com"# >/tmp/list_external_email.txt
>/tmp/list_external_email.txt
echo -n "Start Looking Email Id $knowledgelinux_id ...." >>$Master_log
awk "NR==$Previous_ckeck_line_no, NR==$Currect_line_no_ofLOG" /var/log/zimbra.log | grep -i "to=<$knowledgelinux_id>" | grep -i "from=<" | grep -i "10026"|cut -d ";" -f2 | cut -d ">" -f1| cut -d "<" -f2 | grep -v "knowledgelinux.com" >/tmp/list_external_email.txt
if [ ! -s "/tmp/list_external_email.txt" ];then echo "No Transication from External Domain found">>$Master_log #####-------------------------------------
############send Bounced mail
else
echo "Found Some transication from external Email">>$Master_log
cat /tmp/list_external_email.txt>>$Master_log
#########^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
while read line
do
echo -n "Start sending Email to ID $line ......" >>$Master_log
awk 'BEGIN{print "Subject:Info bounce back !\nFrom:noreply <[email protected]>"}{printf("%s\015\n", $0)}' /message.txt | /opt/zimbra/postfix/sbin/sendmail -t "$line"
if [ $? -eq 0 ];then
echo ".......done" >>$Master_log
else
echo ".....failed" >>$Master_log
fi
done</tmp/list_external_email.txt
####^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
fi ###------------------------------------------------------------------------------
#####################end sending Bounced Email.
done
##############################
echo "$Currect_line_no_ofLOG" >/tmp/Previous_ckeck_line_no.txt

Leave a Reply

Your email address will not be published. Required fields are marked *