Question
How to configure mailboxes to move spam messages to a Spam folder server-wide in Plesk?
Answer
It is not possible to configure mailboxes to move spam messages to a Spam folder server-wide in Plesk via GUI. It can be configured individually for a mailbox.
Please follow the below steps to configure the Spam folder server-wide using CLI utility for Spamassassin.
For existing mailboxes
-
Install Spamassassin in Plesk > Tools & Settings > Updates & Upgrades
-
Log in to Plesk server using SSH.
-
Download or create a bash script /root/script.sh with the following content:
#!/bin/bash
for i in `plesk db -Ne "select name from domains;"`
do
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -Ne"select id from domains where name = '$i';" > /root/${i}_id.txt
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -Ne"select mail_name from mail where dom_id=`cat /root/${i}_id.txt`;" > /root/${i}_mailnames.txt
for n in `cat /root/${i}_mailnames.txt`
do
plesk bin spamassassin -u [email protected]$i -status true
plesk bin spamassassin -u [email protected]$i -action move
done
done -
Grant execution permission to the script:
# chmod +x script.sh
-
Execute the script:
# ./script.sh
For newly created mailboxes
-
Install Spamassassin in Plesk > Tools & Settings > Updates & Upgrades
-
Log in to Plesk server using SSH.
-
Download or create a bash script /root/handler.sh with the following content:
#!/bin/bash
plesk bin spamassassin -u ${NEW_MAILNAME} -status true
plesk bin spamassassin -u ${NEW_MAILNAME} -action move -
Grant execution permission to the script:
# chmod +x handler.sh
-
Go to Plesk > Tools & Settings > Event Manager
-
Click Add Event Handler .
-
Select the event Mail account created and specify the path to the script in the Command field.