Add to Favourites Add to Favourites    Print this Article Print this Article

How to enable SpamAssassin for new accounts

By default (if enabled), DA gives the User the option to enable spamassassin, but it is not turned on by default.

To have it on by default, you can use the user_create_post.sh script to create it for you.

Create:
/usr/local/directadmin/scripts/custom/user_create_post.sh

in it, add:

#!/bin/sh
if [ "$spam" = "ON" ]; then
  DIR=/home/$username/.spamassassin
  mkdir -p $DIR
  UP=$DIR/user_prefs
  if [ ! -s ${UP} ]; then
     echo 'required_score 5.0' > ${UP}
     echo 'report_safe 1' >> ${UP}
     chown $username:$username  ${UP}
     chmod 644 ${UP}
  fi
  chown  ${username}:mail $DIR
  chmod 771 $DIR

  if [ "${domain}" != "" ]; then
     FCONF=/etc/virtual/${domain}/filter.conf
     if [ ! -s ${FCONF} ]; then
        echo 'high_score=15' > ${FCONF}
        echo 'high_score_block=no' >> ${FCONF}
        echo 'where=inbox' >> ${FCONF}
        chown mail:mail ${FCONF}

        echo "action=rewrite&value=filter&user=$username" >> /usr/local/directadmin/data/task.queue
     fi
  fi
fi
exit 0;

Once created, save it and chmod the user_create_post.sh to 755.


The above script can be used to also enable spamassassin for all existing accounts.  You can create another  simple script to do it called (for example) spam.sh with the following code:

#!/bin/sh
for i in `ls /usr/local/directadmin/data/users`; do
{
         for d in `cat /usr/local/directadmin/data/users/$i/domains.list`; do
         {
                     username=$i domain=$d spam=ON /usr/local/directadmin/scripts/custom/user_create_post.sh
         };
         done;
};
done;
exit 0;

save this new spam.sh script, chmod it to 755, and run it once.

Was this answer helpful?

Also Read