Tran Nghi's Site  - Make notes and share experience

Mail filtering and improving the score of sending email



The recommended and easiest way to install Pyzor is with pip:

[email protected]:~# pip install pyzor

In order to upgrade your Pyzor version run:

[email protected]:~# 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/”, line 739, in run_script
self.require(requires)[0].run_script(script_name, ns)
File “/usr/lib/python2.7/dist-packages/pkg_resources/”, 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:

[email protected]:~# wget https://<find the source link from internet, please>/pyzor-0.9.0.tar.gz
[email protected]:~# tar xvf pyzor-0.9.0.tar.gz
[email protected]:~# cd pyzor-0.9.0
[email protected]:~# python build
[email protected]:~# python install

Make sure that you enable spamassassin, and check out Amavis’s configuration

[email protected]:~# 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:

# 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.

# 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

[email protected]:~# 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:

[email protected]:~# postconf -e ‘content_filter = smtp-amavis:[]:10024’

Next edit /etc/postfix/ and add the following to the end of the file:

[email protected]:~# vi /etc/postfix/

# Amavis return path
# inet n    -       n       -       -     smtpd
        -o content_filter=
        -o smtpd_authorized_xforward_hosts=
        -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=
        -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

[email protected]:~# vi /etc/spamassassin/

## 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

Restart all the services:
[email protected]:~# systemctl start spamassassin.service
[email protected]:~# systemctl restart amavis.service
[email protected]:~# systemctl restart postfix.service
[email protected]:~# systemctl restart dovecot.service

Make a test:
[email protected]:~# echo “test” | spamassassin -D pyzor 2>&1 | less

Check by from websites: