How to enable SpamAssassin/rspamd for new accounts


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DirectAdmin
Top Level » Email » Spam

How to enable SpamAssassin/rspamd for new accountsLast Modified: Jun 22, 2019, 7:23 pm
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 grep -m1 -q '^spamd=rspamd$' /usr/local/directadmin/custombuild/options.conf; then
      echo "action=rewrite&value=rspamd&user=${username}" >> /usr/local/directadmin/data/task.queue
  fi

  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.
 
Related Helpfiles
How to enable SpamAssassin on your server.
I wish to change the default spam settings for new domains

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST