Advanced spam filtering – spamassassin myql user preferences

I’ve recently changed the config of my spamassassin and just now noticed that the SPAM folder in my inbox is empty. So what has happened? When changing the config of spamassassin from file to database I only did the half thing. So spamassassin/amavis got stuck with a mixed config and did the default thing: delete spam immediatly. Although I don’t have missed a mail (at least I don’t know of any mail I missed) I prefer having spam mails put in the spam box over deleting them.
So here is the whole thing which I found at

This is a post from my old blog It has been moved here and slightly edited for better readability. It's also been adjusted to the new layout.
The content however is old and might be outdated.

Create a database for spamassassin config

If not done already create a database eg spamassassin with a user spamassassin and a password.
Then we need to create some tables to store the configuration and store the default configuration in it. If you like you can copy my configuration:
Either import the file using phpmyadmin or on the commandline:

mysql -h localhost -u spamassassin < spamassassin.sql.txt

If you have a look in the table userprefs you will note several entries for the user @GLOBAL. These are the default entries for all users. You might want to adjust them to fit your needs.

Tell spamassassin to use the database

Edit /etc/mail/spamassassin/ It needs the information for database access. And it makes sense to give some more default settings. If for some reason the database i

s not accessible for spamassassin it will use these defaults.

##DB Settings##
user_scores_dsn                 DBI:mysql:spamassassin:localhost
user_scores_sql_username        spamassassin
auto_whitelist_factory          Mail::SpamAssassin::SQLBasedAddrList
user_awl_dsn                    DBI:mysql:spamassassin:localhost
user_awl_sql_table              awl
user_awl_sql_username           spammassassin
bayes_store_module              Mail::SpamAssassin::BayesStore::MySQL
bayes_sql_dsn                   DBI:mysql:spamassassin:localhost
bayes_sql_username              spamassassin

##Defaults settings as fallback##
required_score                  5.0
rewrite_header Subject          [SPAM]
tag_level_deftl                 -99
kill_level_deflt                99
report_safe                     1
use_bayes                       1
bayes_auto_learn                1
skip_rbl_checks                 0
use_pyzor                       1
use_razor2                      1
razor_config                    /var/lib/amavis/.razor/razor-agent.conf
use pyzor 1

The last three lines only make sense if you are using razor and/or pyzor.

Adjust spamassassin’s startup options

In order to use the database spamassassin needs to start with the correct options. As it’s not the best idea to edit the startup script /etc/init.d/spamassassin we better use /etc/defaults/spamassassin as suggested in the comments.

OPTIONS="-d -m5 -x -q -Q -u nobody"

and restart spamassassin and amavis.

/etc/init.d/spamassassin restart
/etc/init.d/amavis restart

Check if everything is ok:

ps -eaf |grep spamd

Remove unnecessary options

Not to forget: if you have put any options to /etc/amavis/conf.d/50-user these will override any settings in the database. Just comment or remove them and restart spamassassin and amavis (again).

Now wait for the next spam mail to check if everything is working the way it should. Of course there will be no spam if you need it once in a livetime!

Leave a Reply

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