Resources:
1) Ubuntu – Mail Filtering
2) Ubuntu – PostfixAmavisNew
The recommended and easiest way to install Pyzor is with pip:
root@ubuntu:~# pip install pyzor
In order to upgrade your Pyzor version run:
root@ubuntu:~# pip install –upgrade pyzor
For me, the latest pyzor-1.0.0 seemed to not working on my environment.
Ubuntu 16.04.3
Postfix 3.1.0
Dovecot 0.4.13
SpamAssassin version 3.4.1 running on Perl version 5.22.1
Amavisd-new-2.10.1 (20141025)
Python 2.7.12
Pyzor-1.0.0 was come up with some error, like this:
Traceback (most recent call last):
File “/usr/local/bin/pyzor”, line 4, in <module>
__import__(‘pkg_resources’).run_script(‘pyzor==1.0.0’, ‘pyzor’)
File “/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py”, line 739, in run_script
self.require(requires)[0].run_script(script_name, ns)
File “/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py”, line 1486, in run_script
raise ResolutionError(“No script named %r” % script_name)
pkg_resources.ResolutionError: No script named ‘pyzor’
So, I decided to use Pyzor-0.9.0, hopefully it’s working well.
Hereby is how I start pyzor:
root@ubuntu:~# wget https://<find the source link from internet, please>/pyzor-0.9.0.tar.gz
root@ubuntu:~# tar xvf pyzor-0.9.0.tar.gz
root@ubuntu:~# cd pyzor-0.9.0
root@ubuntu:~# python setup.py build
root@ubuntu:~# python setup.py install
Make sure that you enable spamassassin, and check out Amavis’s configuration
root@ubuntu:~# vi /etc/default/spamassassin
# /etc/default/spamassassin # Duncan Findlay # WARNING: please read README.spamd before using. # There may be security risks. # If you're using systemd (default for jessie), the ENABLED setting is # not used. Instead, enable spamd by issuing: # systemctl enable spamassassin.service # Change to "1" to enable spamd on systems using sysvinit: ENABLED=1 # Options # See man spamd for possible options. The -d option is automatically added. # SpamAssassin uses a preforking model, so be careful! You need to # make sure --max-children is not set to anything higher than 5, # unless you know what you're doing. OPTIONS="--create-prefs --max-children 5 --helper-home-dir" # Pid file # Where should spamd write its PID to file? If you use the -u or # --username option above, this needs to be writable by that user. # Otherwise, the init script will not be able to shut spamd down. PIDFILE="/var/run/spamd.pid" # Set nice level of spamd #NICE="--nicelevel 15" # Cronjob # Set to anything but 0 to enable the cron job to automatically update # spamassassin's rules on a nightly basis CRON=0
root@ubuntu:~# vi /etc/amavis/conf.d/15-content_filter_mode
# This file was automatically installed on 2018-01-09T15:20:07.018374 use strict; # You can modify this file to re-enable SPAM checking through spamassassin # and to re-enable antivirus checking. # # Default antivirus checking mode # Please note, that anti-virus checking is DISABLED by # default. # If You wish to enable it, please uncomment the following lines: @bypass_virus_checks_maps = ( \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re); # # Default SPAM checking mode # Please note, that anti-spam checking is DISABLED by # default. # If You wish to enable it, please uncomment the following lines: @bypass_spam_checks_maps = ( \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re); 1; # ensure a defined return
For Postfix integration, enter the following from a terminal prompt:
root@ubuntu:~# postconf -e ‘content_filter = smtp-amavis:[127.0.0.1]:10024’
Next edit /etc/postfix/master.cf and add the following to the end of the file:
root@ubuntu:~# vi /etc/postfix/master.cf
# Amavis return path
#
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
-o smtpd_delay_reject=no
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o smtpd_restriction_classes=
-o mynetworks=127.0.0.0/8
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks
-o local_header_rewrite_clients=
smtp-amavis unix - - - - 1 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
root@ubuntu:~# vi /etc/spamassassin/local.cf
## Pyzor #use_pyzor 1 #pyzor_path /usr/bin/pyzor ifplugin Mail::SpamAssassin::Plugin::Pyzor use_pyzor 1 pyzor_path /usr/local/bin/pyzor pyzor_options --homedir /etc/mail/spamassassin/.pyzor endif
Restart all the services:
root@ubuntu:~# systemctl start spamassassin.service
root@ubuntu:~# systemctl restart amavis.service
root@ubuntu:~# systemctl restart postfix.service
root@ubuntu:~# systemctl restart dovecot.service
Make a test:
root@ubuntu:~# echo “test” | spamassassin -D pyzor 2>&1 | less
Check by from websites:
https://www.mail-tester.com/
or
https://www.unlocktheinbox.com/mail-tester/