By default, when you add new user in Directadmin, Spamassassin is disabled. Some users are not aware about Spamassassin, so they’ll have it disabled and will receiving a lot of spam. It is good practice to enable Spamassassin by default and also set some settings. You can do that by adding below code in your /usr/local/directadmin/scripts/custom/user_create_post.sh script. The first step is well described on Directadmin documentation. But you may also want to define some parameters for Spamassassin when user is created. It’s really simple. You can do that by manipulating filter.conf file. Steps below are preformed on Directadmin running on FreeBSD. It should be the same for Linux also.
In this example I want that on user creation:
- spam goes to appropriate spam folder,
- set custom high spam score value to 15,
- delete high scoring spam (value of 15 and above),
- rewrite subject of spam message with *****SPAM*****.
Just add code bellow in your user_create_post.sh script. You can remove comments.
## Enable Spamassassin, create needed files and give them appropriate permissions
if [ "$spam" = "ON" ]; then
DIR=/home/$username/.spamassassin
mkdir $DIR
touch $DIR/user_prefs
chown ${username}:mail $DIR
chmod 771 $DIR
chown $username:$username $DIR/user_prefs
chmod 755 $DIR/user_prefs
touch $DIR/spam
chown mail:$username $DIR/spam
chmod 660 $DIR/spam
## Here we define some variables for Spamassassin by adding this lines to filter.conf
echo "high_score=15" >> /etc/virtual/$domain/filter.conf
echo "high_score_block=yes" >> /etc/virtual/$domain/filter.conf
echo "where=userspamfolder" >> /etc/virtual/$domain/filter.conf
echo "rewrite_header subject *****SPAM*****" >> /home/$username/.spamassassin/user_prefs
## Adding operation in task queue
echo "action=rewrite&value=filter&user=$username" >> /usr/local/directadmin/data/task.queue
fi
exit 0;
Than when adding new user you can check if everything is configured as it needs to be in Directadmin user control panel, Spamassassin section. You can also configure additional parameters or change setting according to your needs.