Configuring ClamAV + Postfix

I will give an example of installing and configuring the free ClamAV antivirus for checking email messages for viruses.

In Ubuntu/Debian, switch to the root user and complete the installation:

apt install clamav clamsmtp

In the /etc/clamsmtpd.conf file, by default there were the following options, in fact they are enough (you can not change):

OutAddress: 10025
ClamAddress: /var/run/clamav/clamd.ctl
#Header: X-AV-Checked: ClamAV using ClamSMTP
TempDirectory: /var/spool/clamsmtp
PidFile: /var/run/clamsmtp/
#Quarantine: off
User: clamsmtp

Unless we uncomment a couple of lines and specify a script that will notify about viruses:

Header: X-AV-Checked: ClamAV using ClamSMTP
Quarantine: on
VirusAction: /etc/clamav/

Example script:

if [ X`echo $SENDER | egrep $DOMAIN` != "X" ];
else MAILTO=`echo "$RECIPIENTS" | egrep $DOMAIN | tr '\n' ','`$ADMIN

(echo "Virus name: $VIRUS"
echo "Sender: $SENDER"
echo "Recipient(s): $RECIPIENTS"
if [ "x$EMAIL" != "x" ] && [ -f $EMAIL ]
echo "Quarantined to: $EMAIL"
) | cat -v | mail -s "$VIRUS found on mailserver" $MAILTO 

Let’s make the script executable:

chmod +x /etc/clamav/

If you changed the configuration, then restart clamsmtp to apply the changes:

service clamsmtp restart
service clamsmtp status
ps -ef|grep clamsmtp

Make sure that ClamAV is running (otherwise letters will not go with the error “CLAMAV: couldn’t connect to: /var/run/clamav/clamd.ctl: No such file or directory”):

service clamav-daemon status
systemctl is-enabled clamav-daemon.service
systemctl enable clamav-daemon.service
service clamav-freshclam status
systemctl is-enabled clamav-freshclam.service
systemctl enable clamav-freshclam.service
service clamav-freshclam restart
service clamav-daemon restart
ps -ef|grep clamav

At the end of the /etc/postfix/ file, add:

content_filter = scan:[]:10026
receive_override_options = no_address_mappings

In the file /etc/postfix/ add:

scan unix - - n - 16 smtp
  -o smtp_send_xforward_command=yes inet n - n - 16 smtpd
  -o content_filter=
  -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
  -o smtpd_helo_restrictions=
  -o smtpd_client_restrictions=
  -o smtpd_sender_restrictions=
  -o smtpd_recipient_restrictions=permit_mynetworks,reject
  -o mynetworks_style=host
  -o smtpd_authorized_xforward_hosts=

Check the configuration of Postfix and restart it to apply the changes:

postfix check
service postfix restart

See also my articles:
Installing and using ClamAV antivirus
Installing and Configuring Postfix

Leave a comment

Leave a Reply