AntiSpam with spamtrainer on Mac OS Server – El Capitan

So I am still running Mac OS El Capitan Server Edition on my Mac Mini. Recently, the Spam that comes through, has increased again and I wondered if there is any mechanism to implement AntiSpam in Mac OS X.

The Apple Knowledge Base only gives this article:
https://support.apple.com/kb/PH22351?locale=en_US
which is not exactly what I wanted.

Looking further, I came across these links, which proved helpful at the end:

spamtrainer

According to that site the software will do this:

  • spamtrainer assists Mac OS X Server mail services administrators in updating and maintaining their SpamAssassin bayes database.
  • spamtrainer will read the designated HAM and SPAM mailboxes, update the SpamAssassin databases and delete mail that has been learned from.

After downloading the spamtrainer installation script and installing it I did the following:

Check the proper setup of junkmail / nojunkmail

sudo serveradmin settings mail:imap | grep junk

Result:

 mail:imap:junk_mail_userid = "junkmail"
 mail:imap:not_junk_mail_userid = "notjunkmail"

When running spamtrainer now right away, it complains:

Either there is no mailbox called No GUID found for user: junkmail in the mailpartition or it has never been fed with mail.

Either there is no mailbox called No GUID found for user: notjunkmail in the mailpartition or it has never been fed with mail.

So I go an create those users. Starting the Server.app plus adding the needed network accounts „junkmail“ and „notjunkmail“. Further I edit access so that these accounts only have access to the Mail service. Now I add these accounts to Mail so that I have access to them.

Now, finally, when I run

/usr/local/sbin/spamtrainer

it does what it should.

Using the install option I can also have it run as plist item.

>> /usr/local/sbin/spamtrainer -i

Checking if there is a startup item for 'learn_junk_mail' or 'spamtrainer'

There IS a plist for sa_learn.pl

... and it is ENABLED

If you want to use 'spamtrainer' it is RECOMMENDED that this be disabled

Would you like me to disable it for you (yes/no)

yes

'learn_junk_mail and/or sa_learn.pl' item has been disabled'

You can ignore 'No such process' error messages

There IS NO plist for spamtrainer

if you want to use 'spamtrainer' it is recommended that this be added

Would you like me to enable it for you (yes/no)

yes

What time would you like spamtrainer to run (24-hour format)?

Please enter the hour (1)

05

Please enter the minutes (0)

00

Would you like SPAM/HAM messages to be deleted after the learn process? (n)

y 

Would you like to log bayes stats into /var/log/spamtrainer.log? (n)

y

If you would you like to have spamtrainer mail you a report after it runs, then please enter an e-mail address. Enter for no (n)

myemail@myemaildomain.domain

Enter name of mail store with SPAM/HAM mailboxes? Enter for default (default)

Enter name of mailbox with SPAM? Enter for default (junkmail)

Enter name of mailbox with HAM? Enter for default (notjunkmail)

A plist with the following parameters for 'spamtrainer' has been prepared

/usr/local/sbin/spamtrainer -m myemail@myemaildomain.domain -d -l

It will run each day at 05:00:00

Would you like to add and enable it? (yes/no)

yes

The following launchd plist item for 'spamtrainer' has been enabled'

/usr/local/sbin/spamtrainer -m myemail@myemaildomain.domain -d -l

It will run each day at 05:00:00

That is all for installation, now let me see if it does what it should!