Tobias Fischer

Tobias Fischer

software developer

How to add custom Spamassassin rules in Plesk Onyx

One of my email addresses is apparently part of a spam database – and there linked to the wrong name “Nina Steiner”. So any mail that makes it through my spam filter and contains this name is definitely spamĀ  and should be marked as such.

However, with the Spamassassin integration, Plesk Onyx does not provide a feature that allows you to define your own rules for content analysis.

Spamassassin itself supports this feature, which is why I show how to use it on a Plesk managed system.

Plesk lists the following ressources for Spamassassin configuration:

Enable User Rules

By default, the so-called “User Rules” are deactivated in the Spamassassin configuration.

In /etc/mail/spamassassin/local.cf add the following entry:

allow_user_rules 1

Add Filter Rule

In /var/qmail/mailnames/<domain_name>/<mailbox>/.spamassassin/user_prefs add the following lines:

body NINASTEINER /Nina Steiner/i
describe NINASTEINER Nina Steiner Spam
score NINASTEINER 500.0

Although the file contains a warning

#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

it is safe to modify and add your own user rules. Plesk does not overwrite the entire file when changes are made on the web interface, it only changes the individual configuration values.

Learn more about Body Rules in the Spamassassin Docs.

Restart Spamassassin

You should restart Spamassassin after editing both files:

service spamassassin restart

Check The Logs

You can check the mail log /var/log/maillog to verify the functionality:

spamd[10048]: spamd: processing message <testmail@xxxx.yyy> for <mailbox>@<domain_name>:30
spamd[10048]: spamd: identified spam (500.0/4.0) for <mailbox>@<domain_name>:30 in 1.5 seconds, 2094 bytes.
spamd[10048]: spamd: result: Y 500 - HTML_MESSAGE,NINASTEINER,URIBL_BLOCKED scantime=1.5,size=2094,user=<mailbox>@<domain_name>,uid=30,required_score=4.0,rhost=::1,raddr=::1,rport=57806,mid=<testmail@xxxx.yyy>,autolearn=no autolearn_force=no

Perfect, the Body Rule works well!