Directadmin – enable and configure Spamassassin automatically on creating user

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/ 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:

  1. spam goes to appropriate spam folder,
  2. set custom high spam score value to 15,
  3. delete high scoring spam (value of 15 and above),
  4. rewrite subject of spam message with *****SPAM*****.

Just add code bellow in your script. You can remove comments.

## Enable Spamassassin, create needed files and give them appropriate permissions
 if [ "$spam" = "ON" ]; then
 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
 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.

Got Something To Say:

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


I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2023
Hosted by SIEL

About author