Enable Spamassassin for all existing mailboxes

In order to enable Spamassassin for all existing mailboxes you can use the following script:
#!/bin/sh

#Get the list of mailboxes registered in PPA

mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -sNe “select mail.mail_name, domains.name from mail left join domains on mail.dom_id=domains.id” | sed -E ‘s/[[:space:]]+/@/g’ > /tmp/mailboxes_list

#Enable spamassassin for mailboxes

while read mailbox
do
/usr/local/psa/bin/spamassassin -u $mailbox -status true
done < /tmp/mailboxes_list

Posted in centos, email, plesk and tagged .