spamassassin:stopping_spam
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
spamassassin:stopping_spam [2016/11/02 00:33] – peter | spamassassin:stopping_spam [2019/12/04 21:15] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== SpamAssassin - Stopping Spam ====== | ||
- | ===== Install Mail::Audit ===== | ||
- | |||
- | SpamAssassin needs the **Mail:: | ||
- | |||
- | <code bash> | ||
- | perl -MCPAN -e shell | ||
- | cpan> install Mail::Audit | ||
- | cpan> quit | ||
- | </ | ||
- | |||
- | |||
- | ===== Install Spam Assassin Modules ===== | ||
- | |||
- | Install SpamAssassin from CPAN, which will also install all other required modules too. | ||
- | |||
- | <code bash> | ||
- | perl -MCPAN -e shell | ||
- | cpan> install Mail:: | ||
- | </ | ||
- | |||
- | It maybe will ask you for some needed modules that aren't installed yet - Answer yes and Perl will fetch and install them, too. | ||
- | |||
- | <code perl> | ||
- | cpan> quit | ||
- | </ | ||
- | |||
- | |||
- | |||
- | ===== Run the recommended tests ===== | ||
- | |||
- | First look if the install succeded by running: | ||
- | |||
- | <code bash> | ||
- | which spamassassin | ||
- | / | ||
- | </ | ||
- | |||
- | If you don't get a right answer something failed... or your PATH-variable isn't set right... | ||
- | |||
- | Now lets scan a no spam mail with | ||
- | |||
- | <code bash> | ||
- | spamassassin -t < | ||
- | </ | ||
- | |||
- | Look for a line like this in the output: | ||
- | |||
- | < | ||
- | X-Spam-Status: | ||
- | </ | ||
- | |||
- | Okay fine - now try a bad spam message: | ||
- | |||
- | <code bash> | ||
- | spamassassin -t < | ||
- | </ | ||
- | |||
- | which should produce some lines like that: | ||
- | |||
- | < | ||
- | X-Spam-Status: | ||
- | X-Spam-Flag: | ||
- | </ | ||
- | |||
- | Okay everything seems working... that was the easy part :-) | ||
- | |||
- | |||
- | |||
- | ===== The wrapper script ===== | ||
- | |||
- | For use with Exim here is a small Perl script which implements the Mail::Audit and the Mail: | ||
- | |||
- | <code perl> | ||
- | # | ||
- | # This is an small wrapper script around Mail:: | ||
- | # with the exim MTA. | ||
- | # Modified to eliminate the buggy Mail::Audit use. | ||
- | # This modification also eliminates the need to re-submit the message | ||
- | # to Exim for delivery to the mail spool. Requires localuser director | ||
- | # to use the spamcheck transport so it knows where to append to. | ||
- | # It is released under the Terms of GNU General Public License (GPL) so | ||
- | # use at your own risk! | ||
- | |||
- | use Mail:: | ||
- | use Mail:: | ||
- | |||
- | $savespam = 1; #1/0 should spam be saved centrally? | ||
- | $spamfile = '/ | ||
- | #that nasty spam? Be sure this mailbox | ||
- | #is writable by the user who runs this | ||
- | #script (e.g. mail) | ||
- | #These are given as command line arguments by exim: | ||
- | $sender = shift(@ARGV); | ||
- | $sender = '<>' | ||
- | $recpt = ''; | ||
- | while (@ARGV){ | ||
- | $recpt = $recpt.' | ||
- | } | ||
- | |||
- | ####### Main script ########################################################### | ||
- | |||
- | $mail = Mail:: | ||
- | |||
- | $spamtest = Mail:: | ||
- | $status = $spamtest-> | ||
- | |||
- | #Add the X-Spam Headers: | ||
- | $status-> | ||
- | #Auto Report to Vipul' | ||
- | $status-> | ||
- | |||
- | if ($status-> | ||
- | if ($savespam) { | ||
- | $mail-> | ||
- | } else { | ||
- | $mail-> | ||
- | } | ||
- | } else { | ||
- | $mail-> | ||
- | } | ||
- | </ | ||
- | |||
- | **NOTE**: | ||
- | |||
- | <code bash> | ||
- | touch / | ||
- | chmod 660 / | ||
- | chown mail:mail / | ||
- | </ | ||
- | |||
- | |||
- | ===== Exim Transport Section ===== | ||
- | |||
- | At the end of Exim's transport section add the following: | ||
- | |||
- | < | ||
- | #Spam Assassin | ||
- | spamcheck: | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | # for debugging change return_output to true | ||
- | | ||
- | | ||
- | user = mail | ||
- | group = mail | ||
- | path = "/ | ||
- | | ||
- | </ | ||
- | |||
- | **NOTE**: | ||
- | |||
- | |||
- | ===== Exim Directors Section ===== | ||
- | |||
- | If you've installed the Amavis virus scanner you have to modify the condition statement in its director entry like followed: | ||
- | |||
- | < | ||
- | # condition = "${if eq {$received_protocol}{scanned-ok} {0}{1}}" | ||
- | # I changed the above to the one below because I have a second check | ||
- | # for spam after the antivirus. This is needed to avoid an infinite | ||
- | # loop - do not virus scan again when the mail comes back from the | ||
- | # spam checker: | ||
- | condition = "${if or{ {eq {$received_protocol}{scanned-ok}} {eq {$received_protocol}{spam-scanned}} } {0}{1}}" | ||
- | </ | ||
- | |||
- | This ensures that a mail coming from the spam scan will not be scanned again for viruses. Be sure to change that or you will get an infinite mail loop! | ||
- | |||
- | Now add a new director at the top of the Directors section (but right after the Amavis director if installed!!): | ||
- | |||
- | < | ||
- | #Spam Assassin | ||
- | spamcheck_director: | ||
- | | ||
- | | ||
- | | ||
- | </ | ||
- | |||
- | Okay that's it. We will not add a router entry as we don't want to check our own mails for spam :-). Now open a console with | ||
- | |||
- | <code bash> | ||
- | tail -f / | ||
- | </ | ||
- | |||
- | And send some mail to your local users. | ||
- | |||
- | What else? | ||
- | |||
- | Copy the **spamassasin.cf** to /etc if you want to adjust the scores of the used spam tests. | ||
- | |||
- | **NOTE**: | ||
- | |||
- | |||
- | |||
- | ===== References ===== | ||
- | |||
- | http:// | ||
- | |||
- | http:// | ||
- | |||
- | http:// |
spamassassin/stopping_spam.1478046811.txt.gz · Last modified: 2020/07/15 09:30 (external edit)