By default, when you add new user in Directadmin, Spamassassin is disabled. Some users may not know about Spamassassin, so they’ll have it disabled and will receiving a lot of spam. So it may be good practice to enable Spamassassin by default. 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 sites. But you may also want to define some parameters for Spamassassin “on the fly”. You can do that by manipulating filter.conf file.
In this example I want that on user creation:
- spam goes to appropriate users spam folder,
- I don’t want to delete high scoring spam,
- I want to rewrite subject of spam email with *****SPAM*****.
Just add below code in your user_create_post.sh script. And remove script comments (##).
## We 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 some lines to filter.conf echo “high_score=15” >> /etc/virtual/$domain/filter.conf echo “high_score_block=no” >> /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;