====== Use SpamAssassin with the Synchronet Mail Server ======

The Synchronet [[:server:mail|SMTP Server]] may use a SpamAssassin server ([[http://spamassassin.apache.org/full/3.1.x/doc/spamd.html|spamd]]) to rate received messages and tag or even reject them based on the results. 

===== Installation =====

When installing SpamAssassin, make sure you enable the ''spamd'' (daemon).

==== Windows ====

Apparently, [[http://wiki.apache.org/spamassassin/SpamdOnWindows|it is possible]] to run ''spamd'' on Windows, but *nix OSes are much preferred.

==== Linux ====

On some Linux distributions, you may enable the SpamAssassin daemon (spamd) using ''chkconfig'' command:

  chkconfig --add spamassassin
 

On some Linux distributions, you may start/stop/query the SpamAssasin daemon (spamd) using the ''service'' command: 

  service spamassasin start
 
Or by directly executing the init script:

  /etc/init.d/spamassassin start
 

Don't forget to create a daily cron job to update your SpamAssasin database:

<file /etc/cron.daily/sa-update>
sa-update && /etc/init.d/spamassassin restart
</file>

===== Configuration =====

Synchronet comes with a [[:module:spamc|JavaScript implementation]] of the SpamAssassin spamd client (''[[module:spamc]]'').

To enable this client as a Synchronet //External Mail Processor//, edit your ''[[dir:ctrl]]/[[config:mailproc.ini]]'' file, adding or updating the following section:
<file mailproc.ini>
[SPAMC]
Command=spamc.js
AccessRequirements=user equal 0 or guest
ProcessSpam=false
ProcessDNSBL=false
Disabled=false
</file>

The ''AccessRequirements'' key value above tells the Synchronet Mail Server not to execute this mail processor for unauthenticated clients (''user equal 0'') or for the //Guest// user account, if there is one.

The ''ProcessSpam'' and ''ProcessDNSBL'' options tell the Synchronet Mail Server not to execute this mail processor if the message was received from a [[:config:spamblock.cfg|SPAM-blocked]] or [[:config:dns_blacklist.cfg|DNS-Blacklisted]] sender.

Alternatively, you may specify ''To'' and/or ''From'' keys to limit the mail sender and/or recipients for which messages will be processed by SpamAssassin.

==== Command Line ====

The Synchronet [[:module:spamc]] module supports some of the same command line options as the SpamAssassin ''spamc'' program and these may be included (with or without the dashes) in the ''Command'' key value included in the ''[SPAMC]'' section of your ''[[config:mailproc.ini]]'' file:

^Option ^Usage          ^Description^
|d      |''-d //address//'' |Specify IP address of ''spamd'' host (default: ''127.0.0.1'')|
|p      |''-p //port//''    |Specify the TCP port number of the ''spamd'' server (default: 783)|
|u      |''-u //username//''|Specify the user-id that ''spamd'' should run as|
|s      |''-s //bytes//''   |Specify the maximum message size (in bytes) that ''spamc'' will attempt to process (default: 500000)|

In addition, the Synchronet [[:module:spamc]] supports the following command line options:

^Option   ^Usage          ^Description^
|spamonly |''spamonly''   |Modify SPAM messages only (default: modify all messages)|
|reject   |''reject //level//''|Reject SPAM messages over specified score threshold, modify and pass-through HAM|
|debug    |''debug''      |Enable debug log output|

=== Examples ===

Modify and pass-through all messages:
  Command=spamc.js

Modify SPAM messages only, pass-through all:
  Command=spamc.js spamonly

Reject SPAM messages, modify and pass-through HAM:
  Command=spamc.js reject

Reject SPAM messages over specified score threshold (8.0 in this example), modify and pass-through HAM:
  Command=spamc.js reject 8.0

Reject SPAM messages over specified score threshold (8.0 in this example), modify SPAM, and pass-through HAM and SPAM:
  Command=spamc.js reject 8.0 spamonly


===== Training the Bayes Classifier =====

SpamAssassin's Bayesian classifier becomes more accurate the more it is told
which messages are spam and which are legitimate ("ham"). Synchronet includes a
[[module:spamlearn|Bayes trainer]] mail processor (''spamlearn.js'') for training
it by e-mail. The ''spamd'' server must be started with the ''%%--allow-tell%%''
option to accept training.

  * **By e-mail:** configure sysop-gated ''spamlearn'' and ''hamlearn'' addresses,
    then **redirect** (resend, //not// forward) any missed spam or wrongly-tagged
    good mail to them.
  * **From spam-traps:** point your honeypot addresses at ''spamlearn.js'' with the
    ''block'' option so that trap hits both train Bayes and block the sender.

See [[module:spamlearn]] for the mail-processor configuration.

Note that SpamAssassin can also train itself automatically (''bayes_auto_learn''),
but it decides what is spam or ham from its non-Bayes rules -- so mail from a
throwaway domain that passes its own SPF/DKIM/DMARC checks can be mislearned as
ham. Manual and spam-trap training give you more reliable control.

===== See Also =====
  * [[:server:mail|Mail Server]]
  * [[:module:spamc]]
  * [[:module:spamlearn|SpamAssassin Bayes Trainer]]
  * [[:config:mailproc.ini]]
  * [[:howto:|HowTo index]]

{{tag>antispam email spam}}
