How to enable SpamAssassin (anti-spam) on Plesk Obsidian

Estimated reading time: 2 min

Introduction

In this article, we will describe how you can configure the incoming spam filter of SpamAssassin in Plesk. SpamAssassin in combination with ClamAV is considered a standard setup to protect against viruses and spam. These articles will help with installing and configuring both.

Prerequisites

Step 1: Log in using SSH

You must be logged in via SSH as sudo or root user. Please read this article for instructions if you don’t know how to connect.

Step 2: Install SpamAssassin

plesk installer --select-release-current --install-component spamassassin

Step 3: Configure SpamAssassin

Log in to your Plesk server. On the left pane, click Tools and Settings. View tab Mail and open the Spam Filter settings by clicking on Spam Filter.

Enable “Switch on server-wide SpamAssassin spam filtering”
Enable “Switch on server-wide greylisting spam protection” (highly recommended)
Enable “Apply individual settings to spam filtering”
Make following field blank: “Add the following text to the beginning of subject of each message recognized as spam”
Save by clicking on OK

Plesk Obsidian Spam Filter Settings

Step 4: Enable SpamAssassin by default for new users (optional but recommended)

Create a new script on your server which will be called upon mailbox creation. This script will enable SpamAssassin and change the default action of rewriting the subject to moving the mail to the Spam folder. We will save this script as /usr/local/sbin/mail_create_post.sh

cat <<'EOF' > /usr/local/sbin/mail_create_post.sh
#!/bin/bash
plesk bin spamassassin -u ${NEW_MAILNAME} -status true
plesk bin spamassassin -u ${NEW_MAILNAME} -action move
EOF

Make this script executable:

chmod 700 /usr/local/sbin/mail_create_post.sh

Now go to Plesk. On the left pane, click Tools and Settings. View tab Tools & Resoucres and click on Event Manager. On the next page click on the button + Add Event Handler. On the next page select the option Mail account created as Event. In the field at Command you enter /usr/local/sbin/mail_create_post.sh

Save by clicking on OK.

Plesk Obsidian Adding Event Handler Mail Account Created

From now on whenever a new mail account is created the script /usr/local/sbin/mail_create_post.sh will enable SpamAssassin and change the setting for that user to move spam to the Spam folder.

Step 5: Enable SpamAssassin for all existing users (optional but recommended)

If you want the same settings for all existing mail accounts on your Plesk server just run the following as root in SSH:

for mailbox in $(plesk db -Ne"select concat(m.mail_name,'@',d.name) as email from mail as m left join domains as d on m.dom_id=d.id"); do
plesk bin spamassassin -u $mailbox -status true;
plesk bin spamassassin -u $mailbox -action move;
done

Conclusion

Congratulations, you have now configured incoming spam filters with SpamAssassin.

Was this article helpful?
Dislike 0
Views: 54

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *

snel-knowledgebase