Loading...

Knowledge Base

Train SpamAssassin

You can train SpamAssassin to behave like you want it to... and customer Nathan Olson (thanks Nathan!) broached this topic in an old forum post about SpamAssassin training options.

Let's get started:

  1. Make sure your server has perl module DB_File installed; if it doesn't get in touch with us.

  2. Make two new folders in your IMAP/webmail system called 'spam' and 'ham'
    Note: Spam is where you put spam you find, and ham is where you put examples of good mail (and misfires from the Spam folder). You can also use your inbox for this if you want.

  3. After activating Spam Assassin, log into your FTP account and change to 'home/.spamassassin'

  4. Open the file marked 'user_prefs' and at the bottom of the document, append these rules:

    auto_learn 1
    ok_languages en
    ok_locales en
    report_safe 1
    required_score 8
    use_bayes 1
    use_dcc 1
    use_pyzor 1
    use_razor2 1

  5. Change to the directory 'home/public_html/cgi-bin' and create a document with 755 as permissions called 'spam.sh'

  6. spam.sh:

    #!/bin/sh
    #These are comments, they will give instructions on how to use the script.

    echo "Learning SPAM"

    #Put your domain here
    domain=yourdomain.com

    DNAME="$HOME/mail/$domain/"
    for USER in $(ls $DNAME)
    do
    echo ""
    echo "Processing $DNAME$USER"
    /usr/local/cpanel/3rdparty/bin/sa-learn --spam --showdots $DNAME/$USER/.spam/cur/
    /usr/local/cpanel/3rdparty/bin/sa-learn --spam --showdots $DNAME/$USER/.Junk/cur/

    #If you use a spam collection folder other than .spam or .Junk, simply uncomment the following line (remove the #) and edit the folder path:
    #/usr/local/cpanel/3rdparty/bin/sa-learn --spam --showdots $DNAME/$USER/spamfoldernamehere/
    /usr/local/cpanel/3rdparty/bin/sa-learn --ham --showdots $DNAME/$USER/.ham/cur/

    #This will delete the SPAM and move HAM back to your inbox.

    rm -rf $DNAME/$USER/.spam/cur/*

    #Place # next to mv and delete # next to rm below if you would prefer
    #to delete ham instead of moving it back to inbox.
    #It seems easier to just put it back as you identified that it is mail you want.

    mv $DNAME/$USER/.ham/cur/* $DNAME/$USER/cur/ > /dev/null 2>&1
    #rm -rf $DNAME/$USER/.ham/cur/*

    done
    echo "Done"

  7. Log into cPanel and click Cron Jobs

  8. Input your email address so that the results of the two cron scripts will be returned to you each day

  9. After selecting 'Advanced (Unix Style)' input the following (using your account name where it says 'accountname'):
    Note: if Advanced (Unix Style) isn't available as an option, just proceed with inputting the following info.

    0 5 * * * /home/accountname/public_html/cgi-bin/spam.sh

    Note: where 'accountname' is the cPanel account name.

Did you find this article helpful?

 
* Your feedback is too short

Loading...