How-to Install Spamassassin and Postgray on Ubuntnu 12.04 Zpanel 10.10

Here is a script to install Spamassassin and Postgray on Ubuntnu 12.04 Zpanel 10.10

#!/bin/bash

#####################################################################
#                                                                   #
#                         Version 1.1                               #
#                                                                   #
#                   Installation script for:                        #
#                       - Postgray                                  #
#                       - Spamassassin                              #
#                   on a machine runnning                           #
# - Ubuntu 12.04.3 LTS                        #
#                       - Z-Panel 10.10                             #
#                                                                   #
#               By Rob Groen (info@robgroen.nl)                     #
#                       December 2013                               #
#                                                                   #
# Thanks to:                                                        #
# - acid http://forums.zpanelcp.com/thread-7940.html          #
# - cmos486 http://cmos486.es/redes/279                          #
# - Wupgup     (Wouter)                                              #
#####################################################################


# Install chkconfig
if which chkconfig >/dev/null; then
echo "chkconfig already exist"
else
echo "Installing chkconfig"
#Install utillity to update runlevels in /etc/rc[0-6].d]
apt-get install chkconfig
fi

# Install Postgray
if which postgrey >/dev/null; then
echo "postgrey already exist"
else
echo "Installing postgrey"
# Install Postgrey. See  http://www.greylisting.org
apt-get
install postgrey
sed -i '/^smtpd_recipient_restrictions =/ s/$/ check_policy_service inet:127.0.0.1:10023,/' /etc/zpanel/configs/postfix/main.cf
sed -i 's/options=\"--unix=\/var\/spool\/postfix\/postgrey\/socket\"/options=\"--inet=127.0.0.1:10023 --delay=150\"/g' /etc/init.d/postgrey
service postgrey restart
service postfix reload
chkconfig postgrey on
echo "postgrey installed"
fi


if which spamassassin >/dev/null; then
echo "spamassassin already exist"
else
echo "Installing spamassassin"

# Install SpamAssassin. See http://spamassassin.apache.org/
apt-get
install spamassassin
echo -e "\n" > /etc/mail/spamassassin/local.cf
sed -i '1s/^/required_hits 5.0\n/' /etc/mail/spamassassin/local.cf
sed -i '2s/^/report_safe 0\n/' /etc/mail/spamassassin/local.cf
sed -i '3s/^/required_score 5\n/' /etc/mail/spamassassin/local.cf
sed -i '4s/^/rewrite_header Subject ***SPAM(_SCORE_)***\n/' /etc/mail/spamassassin/local.cf
groupadd spamd
mkdir /var/log/spamassassin
useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
chown spamd:spamd /var/log/spamassassin
sed -i '/^smtp.*inet/ s/$/ -o content_filter=spamassassin/' /etc/zpanel/configs/postfix/master.cf

# Add Spamassasin transport to Postfix main.cf
echo -e "\n#Spamassassin Transport\nspamassassin unix - n n - - pipe user=nobody argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f \${sender} \${recipient}\n" >>/etc/zpanel/configs/postfix/master.cf

# Create Black List and Whist lists
touch /etc/mail/spamassassin/blacklist_to
touch /etc/mail/spamassassin/blacklist_from
touch /etc/mail/spamassassin/whitelist_to
touch /etc/mail/spamassassin/whitelist_from

# Enable SpamAssasin in  /etc/default/spamassassin #ENABLE=1
sed -i 's/^ENABLED=0/ENABLED=1/' /etc/default/spamassassin

# Edit /etc/mail/spamassassin/local.cf and include this
# lines in /etc/mail/spamassassin/local.cf
echo -e "include blacklist_to\n" >>/etc/mail/spamassassin/local.cf
echo -e "include blacklist_from\n" >>/etc/mail/spamassassin/local.cf
echo -e "include whitelist_to\n" >>/etc/mail/spamassassin/local.cf
echo -e "include whitelist_from\n" >>/etc/mail/spamassassin/local.cf


#restart the services
service postfix restart
service postgrey restart
service spamassassin restart

echo "SpamAssassin installed, to test it send a mail from outside with the subject: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"
echo "Your first email will take about 150 seconds to arrive."
fi

echo ""
echo "# =========================================================================="
echo "# Aditional stept to make Spam handeling so much easyer"
echo "# - Move Spam to a Spam folder in IMAP"
echo "# - Learn Spamassassin daily from Spam and Ham"
echo "# - Delete Spam messages older than 7 days from .Spam folder"
echo "# Read instruction at the end of this script or "
echo "# visit www.robgroen.nl/node/315 "
echo "# =========================================================================="



# ==========================================================================
# Aditional stept to make Spam handeling so much easyer
# - Move Spam to a Spam folder in IMAP
# - Learn Spamassassin daily from Spam and Ham
# - Delete Spam messages older than 7 days from .Spam folder
# ==========================================================================
#
#
# -1- Move Spam marked messages to Spam folder
# ----------------------------------------------------------------------------
# After sending a test email with above subject a file like
# /var/zpanel/vmail/DOMAIN/RECIPIENT/dovecot.sieve is made#
#
# Is contains just:
# /* empty script */
#
# Edit that file with your favorite editor (vi?)
#
# remove:
# /* empty script */
#
# add:
# require "fileinto";
#   if exists "X-Spam-Flag" {
#           if header :contains "X-Spam-Flag" "NO" {
#           } else {
#           fileinto "Spam";     
#           stop;
#           }
#   }
#   if header :contains "subject" ["***SPAM"] {
#     fileinto "Spam";     
#     stop;
#   }
#
# -2- Add lines to crontab
# ----------------------------------------------------------------------------
# Add these lines to your root crontab
# Become root
# crontab -e
# add lines
#
# Learn from Ham (Ham is not spam)
# --------------------------------
# # Learn SpamAssassin's Bayesian about HAM classifier daily
# 20 2 * * * find /var/zpanel/vmail/ -maxdepth 3  -name cur -type d -exec sa-learn --ham {} \;#
#
# Learn from missed Spam
# --------------------------------
# # Learn SpamAssassin's Bayesian about SPAM classifier daily
#  30 2 * *  (sa-learn --spam "/var/zpanel/vmail/*/{.Spam,.Junk}/{new,cur}"; rm -f "/var/zpanel/vmail/*/{.Spam,.Junk}/{new,cur}/*";)
#
#
# Empty the Spam folder daily
# --------------------------------
# # Remover old Spam messages from Maildir in directory .Spam and .Junk
# 40 2 * * * find /var/zpanel/vmail/* -iname .Spam -o -iname .Junk -type f -mtime +7 -exec rm {} \

Jan send me thsi message aboud the script on zPanel 10.1.1


Hi Rob,

nice script. Yesterday I tried to install it on our new installed server. I
installed zPanel 10.1.1 on an fresh Ubuntu 12.04 x64.

After install the Script I tried to send the mail for testing... Nothing
happens no sending no catching mails. I got a Backup and gone back.

But I would like to install it running.

Do you or someone else have experience with the newer version of zPanel and
your script.

What I have to look for?

Thanks for your work and help.

Best
jan

I can maken the script work on zPanel 10.1.1


Hi Jan,

I am a Linux expert and it shouldn't be a problem for me to make the script work on zPanel 10.1.1. Unfortunately I have no available server right now to install the zPanel 10.1.1. And I have a little bit low spare time at this moment to build a server for this.

I will ask you (by email) if its possible to use your server for this.

I suppose you meant Ubuntu


I suppose you meant Ubuntu 12.04 instead of 12.4

Was it possible to end email before installing Spamassissan. After a standard installation of ZPanel 10.10 on Ubuntu 12.04 you Postfix won't send any email because of a misconfiguration of postfix.

What does the postfix mail log says?
Send out an email and execute this command on the prompt:
tail /var/log/mail.log

Is postfix running?
service postfix status

postgrey en spamassassin


het gaat om ubuntu 12.4 en zpanel 10.1.0

postgrey en spamassassin


Hoi,

Ik heb deze script geinstalleerd, maar het werkt bij mij niet.
Ik heb de script in een bestand .sh gedaan en als root geinstalleerd.
De installatie is zonder errors gelukt alleen ik kan nu niet meer mails verzenden of ontvangen. enig idee hoe dit kan? Heeft u tips hoe ik dit kan oplossen?

Alvast bedankt.

Mvg,

Misschien kan Rob mij even


Misschien kan Rob mij even mailen voor de wijzigingen (adres zal neem ik aan bij hem bekend zijn als admin).
Zelf kun je mij ook bereiken door te mailen naar script@ mijn gebruikersnaam .nl

Ik wil best helpen, maar elke


Ik wil best helpen, maar elke post van mij wordt tegen gehouden door de website...

Comment viewing options
Select your preferred way to display the comments and click "Save settings" to activate your changes.
Post new comment
The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.