in Mail, Monitoring, MySQL

Install and configure MailWatch monitoring tool for MailScanner

MailWatch for MailScanner is a web-based front-end to MailScanner written in PHP, MySQL and JpGraph. It comes with a CustomConfig module for MailScanner which causes MailScanner to log all message data (excluding body text) to a MySQL database which is then queried by MailWatch for reporting and statistics.

1. Install Apache2, MySql server and PHP5 with required modules. You may already have some or all of these packages installed.

apt-get install apache2 php5-cli php5 mysql-server libdbd-mysql-perl php5-gd php5-mysql libapache2-mod-php5

2. Download the latest version of MailWatch


At the time this tutorial was written, version 1.0.5 was the latest version. Check this location for latest version:

3. Extract and enter the mailwatch directory

tar zxvf mailwatch-1.0.5.tar.gz
cd mailwatch-1.0.5

4. Create the database and tables

mysql -p < create.sql

5. Create a MySql user used for MailScanner logging (mysql -u root -p)

GRANT ALL ON mailscanner.* TO '{username}'@'localhost' IDENTIFIED BY '{password}';

Replace {username} and {password} with a username and password of choice.

6. Configure the MailScanner logger (pico

my($db_user) = '{username}';
my($db_pass) = '{password}';

On line 43 and 44, input your MySql user created in step 5

7. Move the MailScanner logger to correct directory

mv /usr/share/MailScanner/MailScanner/CustomFunctions/

8. Edit Mail Scanner config to enable MailWatch logger (pico /etc/MailScanner/MailScanner.conf)

Always Looked Up Last = &MailWatchLogging

9. Create a MailWatch web admin user (mysql -u root -p)

USE mailscanner;
INSERT INTO users VALUES ('{username}',md5('{password}'),'Administrator name','A','0','0','0','0','0');

Replace {username} and {password} with a username and password used to enter the web interface.

10. Move the web interface to the web server's root

mv mailscanner /var/www/mailwatch

11. Make the temp and cache directories writeable

chmod 777 /var/www/mailwatch/temp
chmod 777 /var/www/mailwatch/images/cache

12. Copy the example config file

mv /var/www/mailwatch/conf.php.example /var/www/mailwatch/conf.php

13. Configure the web interface (pico /var/www/mailwatch/conf.php)

define('DB_USER', '{username}');
define('DB_PASS', '{password}');
define('MAILWATCH_HOME', '/var/www/mailscanner');

Type the MySql username and password created in step 5

14. Install PEAR PHP framework

apt-get install php-pear

15. Install required PEAR packages

pear install DB
pear install DB_Pager
pear install Mail_mimeDecode

16. On line 37, add /usr/share/php to the mailwatch include path (pico /var/www/mailwatch/functions.php)


17. Restart Apache and MailScanner

/etc/init.d/apache2 restart
/etc/init.d/mailscanner restart

18. You're all set. Enter the web interface at this location http://yourserver/mailwatch

Write a Comment


  1. very good tutorial, but friend, I get stuck at 16 beacuse I can’t see how to edit the line 37 wich you have mentioned to be edited and added the /usr/share/php line to the include_path, so it will be great if you edit your nice tutorial and fix that! Thanks for this very easy tutorial.

  2. well if someone has the same problem that I had here is the complete line:

    16. On line 37, add /usr/share/php to the mailwatch include path (pico /var/www/mailwatch/functions.php)


    Note that what you have to add is the content after xmlrpc word, so just make your file looks like the line above.

  3. Hi, just a small point on my squeeze, just followed your tutorial and btw many thanks for it 🙂

    think to edit MailScanner.conf, and set Virus Scanners = clamd, in my case, auto was not working