📜 ⬆️ ⬇️

SpamAssassin Training

It's no secret that Gmail is the best service of its kind. Filtering letters is very accurate. Users of this service have long forgotten such a scary word as "Spam".

Among the corporate sector, the problem of a large number of spam emails is very relevant. To combat this problem we have to come to very ambiguous measures. There is enough information in the network, which gathered together, you can get a good spam filter. In this case, I will try to describe the learning process of all known SpamAssassin by means of the Gmail service. As a result, we will get the same behavior of SpamAssassin on the letters, as if they came to you on Gmail.

Google is very sensitive to its intellectual property and does not disclose the details of their postal service, but you can get out of the situation by adapting your mail in the manner of a “good corporation”.

So, it is assumed that you have a mail server. Configured and fully functioning. Prescribed PTR and DMARC. SPF, DKIM and running but not trained SpamAssassin are configured. Partly - these actions are enough to significantly reduce the number of unwanted correspondence, but still, we will not stop there.
')
To implement, you must install fetchmail:

#apt-get install fetchmail

This utility will serve as an intermediary between Gmail and our mail server.

Set up fetchmail.

First, we need to create a configuration file:

#touch /root/.fetchmailrc

#vi /root/.fetchmailrc

With the following content:

poll imap.gmail.com protocol imap port 993 and options no dns,
user "[vashadres@gmail.com](mailto:vashadres@gmail.com)" options ssl,
password "vashparol",
fetchall,
pass8bits,
nokeep,
folder "[Gmail]/Spam",
mda "/usr/bin/sa-learn --spam"

poll imap.gmail.com protocol imap port 993 and options no dns,
user "[vashadres@gmail.com](mailto:vashadres@gmail.com)" options ssl,
password "vashparol",
fetchall,
pass8bits,
nokeep,
folder "[Gmail]/Important",
mda "/usr/bin/sa-learn --ham"

Important! The mailbox must have an English interface, because fetchmail has Cyrillic issues.

Everything is clear with the “spam” folder, but with the “INBOX” folder it is not so simple. Gmail simply does not have it, but when you connect via IMAP, we are dealing with so-called “labels”. Therefore, we specify the folder “Important”.

Next, go to the alias file (I have Postfix installed, so I will give an example on its configuration) and point the forwarding letters to the newly created or already existing Gmail address. I recommend to create a new one, because The old address may contain any rules from the “past” that may incorrectly correct SpamAssassin when training.

#vi /etc/aliases


We write the following:

: , root

vasya: vasya, root

When all users were registered and sent to the root user, all this correspondence should go to our Google Mailbox:

At the end of the alias file we should write:

root: vashadres@gmail.com

Important! So you need to register each box available in the system. You may not send all messages to the root user, but this will make your life easier in the future.

Save the file. Is done. From now on, all letters arriving to users will be duplicated on vashadres@gmail.com, which in turn will correctly sort out all letters.

Now, having received a sufficient number of letters to the mailbox from Google, it is necessary to mark them so that, thanks to the labels, the letters from the INBOX folder are duplicated into the Important folder by clicking the arrow next to the letter header. It should turn yellow. This is a one-time action, which is rarely needed in the future. All new letters will be marked as “Important” and duplicated in the folder we need.

It remains for us to say fetchmail to collect all the letters from Google and show SpamAssassin.

# / usr / bin / fetchmail -f /root/.fetchmailrc -v

All is ready. Having been trained in several thousand letters - you can be sure that your mail will behave in the same way as Google’s quality mail service.

Update: To avoid leakage of important information, you can obviously set up a server. Create a spam user and place in the signature on the forums. After some time, spam bots will do their job of scanning and spam will start to go to this mailbox. Every day more and more. Train SpamAssassin in this way and then put the combat and trained server into operation.

Source: https://habr.com/ru/post/232079/


All Articles