Servers 101: Emailify Your Server Part 6: clamav
In the previous part, we configured SpamAssassin to help ourselves a little bit with spam. Now we are going to install and configure ClamAV as an antivirus for our email. This is completely optional, as you should have an antivirus in your computer and take this load off of your server! This can make a big difference on how powerfull the server you need to rent.
Other stuff in the Server 101 series:
- Intro and getting into your server - Single Article
- Basic Server Security - 3 Parts
- Setting up a Web Server - 4 Parts
- Managing Your Server - 4 Parts
- caddy - Lightweight Web Server - 1 Part
Installing clamav
apt-get install clamav clamav-daemon clamsmtp
Configuring ClamSMTP
Edit clamsmtp.conf: nano /etc/clamsmtpd.conf
We need to uncomment the line reading Header: X-AV-Checked: ClamAV using ClamSMTP. Just remove the hashtag (#) infront of it!
In the same file, we need to change the user clamsmtp will run as. Locate User: clamsmtp and change it to User: clamav.
Save and exit.
Now we have to change the owner of a couple of folders
chown -R clamav:clamav /var/spool/clamsmtp
chown -R clamav:clamav /var/run/clamsmtp
Configuring Postfix to use clamsmtp
We now need to edit main.cf: nano /etc/postfix/main.cf
add this line at the end:
content_filter = scan:127.0.0.1:10026
Save and exit (the IP and port above, are the default for clamsmtp).
Now, we move to the master.cf: nano /etc/postfix/master.cf
Copy and paste these lines at the end of the file:
scan unix - - n - 16 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n - n - 16 smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks_style=host
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
Save and exit!
Restart!
Restart clamav-daemon, clamsmtp and postfix:
service clamav-daemon restart
service clamsmtp restart
service postfix restart
We are done! clamav is already updating the virus definitions in the background via freshclam, and will be checking our emails via clamsmtp.
This post concludes the "Mailify series".
If you need a place to host your servers consider Vultr, Digital Ocean and BuyVM.
These are affiliate links. If you sign up through them, you support me and I will have more free time to write more content like this.
Also If you signup for Digital Ocean through my affiliate link, you will get $10 to try them out. Note: to battle abusers of this offer, you'll have to make a $5 deposit via Paypal or add your credit/debit card, so they can confirm that you are a new user. I did a deposit via Paypal to test them out, and then I added my credit card so I won't have to deposit money manually every now and then.

Hey @dimitrisp nice post, I haven't seen many linux post on here, its always a great read when covering one of the best operating systems around. You've got my upvote.
If you have anything you would like to know, feel free to leave a comment, and I will reply -or make a post about it!-
Thanks :)
Definitely worth an upvote and a resteem :]
Great info !
I used a little bit of ubuntu in the past and also managed to create a freenas local file server .
This one is more advanced i think but thanks for your effort !