Prerequisite

Resolving MailScanner Dependencies

  1. Run the following cpan commands one at a time (i.e. to see if they are successfully installed):
    sudo cpan -i Filesys::Df
    sudo cpan -i IO::Stringy
    sudo cpan -i DBI
    sudo cpan -i Net::CID
    sudo cpan -i Sys::SigAction
    sudo cpan -i MIME::Parser
    sudo cpan -i Archive::Zip
    sudo cpan -i OLE::Storage_Lite
    sudo cpan -i DBD::SQLite
  2. Install the following packages:
    sudo apt-get install unrar
    sudo apt-get install sqlite

Installing Clamav Antivirus

Run the following command:

sudo apt-get install clamav clamav-daemon

Integrating Clamav to MailScanner

  1. Update the /etc/MailScanner/MailScanner.conf to have the fields Virus Scanner and Clamd Socket to become as follows:
    Virus Scanner = clamd
    Clamd Socket = /var/run/clamav/clamd.ctl
  2. Restart the mailscanner service with the following command:
    sudo service mailscanner restart
  3. Update the file /etc/apparmor.d/usr.sbin.clamd to have the following entries:
      /var/spool/MailScanner/** rw,
      /var/spool/MailScanner/incoming/** rw,
  4. Restart the apparmor service with the following command:
    sudo systemctl restart apparmor.service

Installing and Updating Spamassassin

Run the following commands:

sudo apt-get install spamassassin
sudo sa-update
sudo service spamassassin start

Integrating MailScanner to Postfix

  1. Open the file /etc/postfix/main.cf for editing and add the following line and save:
    header_checks = regexp:/etc/postfix/header_checks
  2. Create the file /etc/postfix/header_checks with the following:
    /^Received:/ HOLD
  3. Open the file /etc/MailScanner/MailScanner.conf for editing and update with the following if necessary:
    Run As User = postfix
    Run As Group = postfix
    Incoming Queue Dir = /var/spool/postfix/hold
    Outgoing Queue Dir = /var/spool/postfix/incoming
    MTA = postfix
  4. Open the file /etc/MailScanner/defaults for editing and update with the following if necessary:
    run_mailscanner=1
  5. Update the group of /var/spool/MailScanner to mtagroup and allow the it write permission as follows:
    sudo chown :mtagroup /var/spool/MailScanner
    sudo chmod 775 MailScanner
  6. Prepare spamassassin's directory using the following commands:
    sudo mkdir /var/spool/MailScanner/spamassassin
    sudo chown postfix /var/spool/MailScanner/spamassassin
  7. Update the permission of the MailScanner's incoming and quarantine folders with the following commands:
    sudo chown postfix.mtagroup /var/spool/MailScanner/incoming
    sudo chmod 770 /var/spool/MailScanner/incoming
    sudo chown postfix.mtagroup /var/spool/MailScanner/quarantine
  8. Restart the mailscanner service with the following command:
    sudo service mailscanner restart

Related Post
Configuring Email Server with Postfix and Dovecot: