spamtrainer

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.
It has an array of additional functions. Among them the possibility to backup/restore your bayes database and many more.
This script is written for OS X 10.8.x, 10.9.x , 10.10.x, 10.11.x, 10.12.x and 10.13.x with Server 2.x/3.x/4.x/5.x. A separate release is available for earlier OS X versions.

See current changelog for a complete list of fixes and additions.
Please read our FAQs as well.

spamtrainer is a free download.

 

 

87 replies
Newer Comments »
  1. Jos
    Jos says:

    For others wondering prior to the Mavericks upgrade: I just upgraded to Mavericks and my mail is still being flagged correctly as spam, except the training part is no longer scheduled and can’t be rescheduled using -i as the script will tell you the OS isn’t supported.

    Reply
  2. Gavin
    Gavin says:

    Hi. Do you know if spamtrainer works under OS X Server 4.0 / Yosemite? I know the script halts if you try to run it on a Yosemite machine, but I’ve got it installed on a Mavericks server, just wondered if it is likely to run if I upgrade the server to 4 – i.e. will an ‘in place’ installation continue to work…? If not, is there something I can do to bend the script to work?

    Reply
  3. rob
    rob says:

    Does this work out of the box ?
    if so does each user need to create a ham and spam folder or are these folders automatically created ?

    Reply
  4. Mike
    Mike says:

    I noticed that the “startup_check_new” function doesn’t work correctly on Yosemite with Server 4.1. The grep for “learn_junk_mail” doesn’t find anything because Apple seems to have changed the script name from “learn_junk_mail” to “sa_learn.pl”. It also seems to be disabled by default, so the fact that the script can’t find it won’t matter to most people. I don’t know when this was changed since I went straight from 10.6.8 to 10.10.3 (not without some difficulty).

    Reply
  5. Chris Jenkins
    Chris Jenkins says:

    I’m guessing that this is not yet compatible with El Capitan (due to SIP) and OS X Server 5.0.x? If not, any plans for a compatible version?

    Thanks, Chris

    Reply
  6. Paul
    Paul says:

    I have installed this, but when I run:

    /usr/sbin/spamtrainer -i

    I get this:

    Last login: Mon Nov 30 09:39:11 on ttys000
    work:~ tweakadmin$ sudo /usr/sbin/spamtrainer

    +——————————————————————–+
    | |
    | spamtrainer |
    | |
    | Version 2.1.0 |
    | |
    | Copyright (c) 2005 – 2014 |
    | Athanasios Alexandrides |
    | |
    +——————————————————————–+

    Starting spamtrainer…

    Training from user folders
    Learning SPAM…
    Learned new SPAM (junk mail)
    Learning HAM…
    Learned new HAM (not junk mail)
    Syncing SpamAssassin Database
    Displaying SpamAssassin Database Stats
    0.000 0 2604 0 non-token data: spam
    0.000 0 40895 0 non-token data: ham
    Done!
    Output produced by spamtrainer Version 2.1.0

    You are using spamtrainer to train and maintain your content filter.
    If you find the software useful, please spread the word. Thank you!
    See: http://topicdesk.com/

    work:~ tweakadmin$ /usr/sbin/spamtrainer -i

    +——————————————————————–+
    | |
    | spamtrainer |
    | |
    | Version 2.1.0 |
    | |
    | Copyright (c) 2005 – 2014 |
    | Athanasios Alexandrides |
    | |
    +——————————————————————–+

    spamtrainer must be run as root user.

    work:~ tweakadmin$ sudo /usr/sbin/spamtrainer -i

    +——————————————————————–+
    | |
    | spamtrainer |
    | |
    | Version 2.1.0 |
    | |
    | Copyright (c) 2005 – 2014 |
    | Athanasios Alexandrides |
    | |
    +——————————————————————–+

    Checking if there is a startup item for ‘learn_junk_mail’ or ‘spamtrainer’

    There IS NO plist for learn_junk_mail

    grep: /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist: No such file or directory
    grep: /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist: No such file or directory
    There IS a plist for spamtrainer
    … and it is ENABLED
    Would you like me to disable it for you (yes/no)
    no

    work:~ tweakadmin$ /usr/sbin/spamtrainer

    +——————————————————————–+
    | |
    | spamtrainer |
    | |
    | Version 2.1.0 |
    | |
    | Copyright (c) 2005 – 2014 |
    | Athanasios Alexandrides |
    | |
    +——————————————————————–+

    spamtrainer must be run as root user.

    work:~ tweakadmin$ sudo /usr/sbin/spamtrainer
    Password:

    +——————————————————————–+
    | |
    | spamtrainer |
    | |
    | Version 2.1.0 |
    | |
    | Copyright (c) 2005 – 2014 |
    | Athanasios Alexandrides |
    | |
    +——————————————————————–+

    Starting spamtrainer…

    Training from user folders
    Learning SPAM…
    Learned new SPAM (junk mail)
    Learning HAM…
    Learned new HAM (not junk mail)
    Syncing SpamAssassin Database
    Displaying SpamAssassin Database Stats
    0.000 0 2604 0 non-token data: spam
    0.000 0 40900 0 non-token data: ham
    Done!
    Output produced by spamtrainer Version 2.1.0

    You are using spamtrainer to train and maintain your content filter.
    If you find the software useful, please spread the word. Thank you!
    See: http://topicdesk.com/

    work:~ tweakadmin$ /usr/sbin/spamtrainer -i

    +——————————————————————–+
    | |
    | spamtrainer |
    | |
    | Version 2.1.0 |
    | |
    | Copyright (c) 2005 – 2014 |
    | Athanasios Alexandrides |
    | |
    +——————————————————————–+

    spamtrainer must be run as root user.

    work:~ tweakadmin$ sudo /usr/sbin/spamtrainer -i

    +——————————————————————–+
    | |
    | spamtrainer |
    | |
    | Version 2.1.0 |
    | |
    | Copyright (c) 2005 – 2014 |
    | Athanasios Alexandrides |
    | |
    +——————————————————————–+

    Checking if there is a startup item for ‘learn_junk_mail’ or ‘spamtrainer’

    There IS NO plist for learn_junk_mail

    grep: /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist: No such file or directory
    grep: /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist: No such file or directory
    There IS a plist for spamtrainer
    … and it is ENABLED
    Would you like me to disable it for you (yes/no)

    How do I get SpamTrainer to create a plist for learn_junk_mail?

    Reply
  7. Robert Chalmers
    Robert Chalmers says:

    I am running Postfix, Spamassassin, dmarc, spf, dkim. using virtual hosts. My mail boxes are in the syntax

    virtual_mailbox_base = /var/mail/vhosts///cur where the actual mail lives.

    This is not a server… will spam trainer work on this type of system?

    Reply
  8. Bob Arene
    Bob Arene says:

    Hi, trying to run spamtrainer 2.2.1 on Mac Mini with OS X Server 10.11.3. When i issue the command sudo /usr/local/sbin/spamtrainer, I get the following permissions error; any idea what I could do to overcome it?

    Starting spamtrainer…

    Training from user folders
    Learning SPAM…
    Learned new SPAM (junk mail)
    Learning HAM…
    Learned new HAM (not junk mail)
    Syncing SpamAssassin Database
    bayes: cannot open bayes databases /Library/Server/Mail/Data/scanner/amavis/.spamassassin/bayes_* R/O: tie failed: Permission denied
    bayes: cannot open bayes databases /Library/Server/Mail/Data/scanner/amavis/.spamassassin/bayes_* R/W: tie failed: Permission denied
    Displaying SpamAssassin Database Stats
    bayes: cannot open bayes databases /Library/Server/Mail/Data/scanner/amavis/.spamassassin/bayes_* R/O: tie failed: Permission denied
    bayes: cannot open bayes databases /Library/Server/Mail/Data/scanner/amavis/.spamassassin/bayes_* R/O: tie failed: Permission denied
    ERROR: Bayes dump returned an error, please re-run with -D for more information
    Done!
    Output produced by spamtrainer Version 2.2.1

    Reply
    • Athanasios Alexandrides
      Athanasios Alexandrides says:

      Looks like you upgraded your server from a previous OS X release. You will need to make sure you fix the permissions for:
      /Library/Server/Mail/Data/scanner/amavis/.spamassassin/
      Set them to _amavisd:_amavisd

      Reply
  9. Major
    Major says:

    Hi,

    i am using SP 2.2.1 on El Capitan 10.11.5 with Server 5.1 and spamtrainer has a problem: it does not delete the spam mails.

    When manually starting with sudo spamtrainer -d, all is fine and learned mails are deleted. Imvoked by the LaunchDaemon it runs, but it does not delete. So there can’t be a permission problem. I double checked the -d option in the plist file. Did not help. No entries in Acivity log but “spamtrainer 2.2.1”. A log should be more comprehensive 😉

    This is the plist-file /Library/LaunchDaemons/com.topicdesk.spamtrainer.plist

    Label
    com.topicdesk.spamtrainer
    ProgramArguments

    /usr/local/sbin/spamtrainer
    -j junkmail
    -n notjunkmail
    -m [email protected]
    -l
    -d

    StartCalendarInterval

    Minute
    30
    Hour
    3

    UserName
    root
    AbandonProcessGroup

    Reply
      • Major
        Major says:

        Hi,

        Manually it works always, as a LaunchDaemon it seems to train, but it does never delete.

        From the CLI i used only spamtrainer -d, not the entire set and it worked always.
        I tried to manually use the entire paramater set from the plist-file and it has deleted all junk after learning. Mail was sent , but after that there was an error:

        unknown: warning: /etc/postfix/main.cf, line 690: overriding earlier entry: config_directory=/etc/postfix

        but there is no previous definition of that path in main.cf. All postfix-config should be in /Library/Server/Mail/Config/postfix for Server.app as far as i know.

        So, this does not seem to affect deletion, because manually it works.

        How do i invert “-d” and “-l” ?

        Reply
  10. Athanasios Alexandrides
    Athanasios Alexandrides says:

    If you manually used it and it worked, then there is no need to invert parameters. Looks more like the launchd item is not running at all at night. Have a look at system.log for that timeframe.
    You can ignore the Postfix error. It is due to path changes in Server 5.

    Reply
    • Major
      Major says:

      Hi,

      it runs every night. I get the mail every morning and there are no errors concerning “spamtrainer” in the log.

      Is there any way to get more logs from spamtrainer than it’s version in the logs ? That logging seems to somewhat needless.

      Reply
  11. Johan Ylinenjarvi
    Johan Ylinenjarvi says:

    Am I the only one that feels like it doesn’t make much of a difference?
    I “train” the filter every day but it feel like get the same spam-mails over and over again.

    Im on OSX 10.10.5 and Server 5.0

    Training from user folders
    Learning SPAM…
    Learned new SPAM (junk mail)
    Learning HAM…
    Learned new HAM (not junk mail)
    Syncing SpamAssassin Database
    Displaying SpamAssassin Database Stats
    0.000 0 19608 0 non-token data: spam
    0.000 0 301923 0 non-token data: ham
    Deleting learned HAM and SPAM
    Done!
    Output produced by spamtrainer Version 2.2.1

    Any ideas?

    Reply
    • M. Jor
      M. Jor says:

      No, you are not the only one. Me too. OSX servers spamassassin never worled for me , since my first server.app. Not a single mail was catched by spamassassin ((with one exception: hard coded blacklist adresses works flawless). The mail and spam configuration under OSX server is a pain in the ass.

      I don’t see any differences in the SPAM-Handling of OSX spamassasin activated or not. Some – but not all- of them even are not “scored” SPAM or HAM – i don’t know why. I am still getting the same f***** SPAM every day. Same SPAM – learned over night again and again- and…forgotten. Most of them do not even get a SPAM-score by Spamassassin. Ist does not seem to see any of them. They are checked (and tagged) by Amavis, but no trace of spamassassin. Yes, i get statistics – wow! – but that’s it. To be precise: i get one more SPAM-related mail additionally – that one of spamtrainer 😀

      Thunderbird saves me – it’s spam recognizsation is MUCH better than this OSX scrap and opened on one desktop it sorts my IMAP-account . But don’t think, that’s the right way.

      But wait – this is NOT spamtrainers problem, because spamtrainer does not the filtering. It only puts spamassassin into training mode at certain times. But it seems to feed a zombie.

      Reply
      • Athanasios Alexandrides
        Athanasios Alexandrides says:

        spamtrainer calls sa-learn (a SpamAssassin utility) to train the Bayesian database. This is only one small part of possible measures to fight spam. A well trained Bayes db will be more accurate in assigning the BAYES_xx scores. It will however not block all spam and it is NOT a blacklist. In other words, feeding the bales DB increases accuracy, it does not black- or whitelist senders.
        There are many configuration options in amavisd.conf and local.cf that will increase spam detection.

        Reply
        • M. Jor
          M. Jor says:

          As i said – the behaviour of Servers.app implementation of Amavis/Spamassassin is NOT a spamtrainer error.

          Spamtrainer seems to do it’s job – but the BAYES-Filtering of Spamassassin seems to be a problem – and that is NOT Spamtrainers job.

          I tried a SPAM-Mail-Test with Byteplant mailsecuritycheck and 6 of 7 were recognized instantly by Amavis/Spamassassin, so it works. But i get real spam from the wild, not that laboratory mice. And that one are not catched. Never.

          Reply
  12. Paul Jacobson
    Paul Jacobson says:

    Any plans for a version that supports Server 5.2/ macOS Sierra?
    I discovered after the update spamtrainer reports that it won’t run.

    With Spamassassin 3.4.1 there is a replacement for AWL called TxRep. It’s disabled by default but reading the man pages it appears to address a lot of the issues caused by AWL. The auto-learning improvements sound like they’ll go a long way to improving the results from using spam trainer.

    https://spamassassin.apache.org/full/3.4.x/doc/Mail_SpamAssassin_Plugin_TxRep.html

    “3. Auto-Learning – in certain situations SpamAssassin may declare a message an obvious spam resp. ham, and launch the auto-learning process, so that the message can be re-evaluated. AWL, by design, did not perform any auto-learning adjustments. This plugin will readjust the stored reputation by the value defined by txrep_learn_penalty resp. txrep_learn_bonus. Auto-learning score thresholds may be tuned, or the auto-learning completely disabled, through the setting txrep_autolearn.”

    Reply
Newer Comments »

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply to Johan Ylinenjarvi Cancel reply

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