Autoresponder for email - Goldfish
Recently I was put up against a challenge to make an auto responder work on our dedicated server that would automatically respond to emails when it has been set to do so. In our case we are running Ubuntu, postfix and roundcube that operate with a MySQL database to serve virtual users and multiple domains. I researched a few things out there, and tried one (YAA! auto responder). Which I couldn't get to work if my life depended on it.
I decided to look into a PHP auto responder since I prefer programming over server side scripting. My search came to an end when I found Goldfish auto responder. After I configured it, I also made a plugin for Roundcube to manage autoresponses through a nice interface rather then straight MySQL or PHPMyAdmin (see link to the next tutorial at the bottom). This tutorial will explain how I configured Goldfish on a Linux server.
Before starting some of the requirements for this to work correctly are:
- Postfix
- Courier
- MySQL database to house virtual users/domains
Here is a great tutorial on how to do just that, found on Slicehost.
Before starting the tutorial, you have to download Goldfish autoresponder script. It can be found here. I downloaded the goldfish-1.1-STABLE.tar.gz. If you want to use the exact source code I used it can be found at the bottom of this article.

First step to the actual configuring Goldfish is to set up the MySQL table that is going to be housing the auto responses for the different emails on your server. You can create the 'autoresponder' table either through terminal on your server or through a client like PHPMyAdmin.
If you are doing this through terminal/SSH you will need to go into mysql first with your root account, and select the database you wish to use when creating the new table for the autoresponder.
You need to execute the following commands:
mysql -u root -pEnter your password for the root user. Once you have logged in you need to select the database you will be adding a new table on. Use the following command:
USE mail;In my case the database for RoundCube/Postfix is named 'mail'. The next step is to create a new table with some SQL. Here is the SQL for creating the table we require:
CREATE TABLE 'autoresponder' ( 'email' varchar(255) NOT NULL default '', 'descname' varchar(255) default NULL, `from` date NOT NULL default '0000-00-00', 'to' date NOT NULL default '0000-00-00', 'message' text NOT NULL, 'enabled' tinyint(4) NOT NULL default '0', 'subject' varchar(255) NOT NULL default '', PRIMARY KEY ('email'), FULLTEXT KEY 'message' (`message`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;If you used terminal to do the following, it should just execute and give no reply - that is when you know all went well. If you are using PHPMyAdmin, just go to the database you created for Postfix and RoundCube, once in the database click the SQL link and copy the table above into the textarea.

After you have successfully created your table in the correct database your output should look something like this when you press 'Structure' tab for the table you have just created. Here is an image to illustrate:

Since we are working with the database, for testing purposes when everything is all set up and good to go we will need an email to test against if it auto-responds. This is what you need to do if you are doing it via terminal, these are the commands you need to do:
mysql -u root -pOnce again enter your password and then do the following:
USE mail;Then you need to enter the following SQL code to insert a sample testing record:
INSERT INTO 'autoresponder' ('email', 'descname', 'from', 'to', 'message', 'enabled', 'subject') VALUES('info@eugenesklyar.com', 'Autoresponder for Eugene Sklyar', '2010-05-10', '2033-01-01', 'I will be out of the office for ever!! Muahahaha', 1, 'Out of the Office');After having the database configured for our autoresponder we need to do the configuration for our server. Before we do anything on the server we need to configure the Goldfish script to talk to our database. Open the autoresponder.php file that you downloaded earlier, and look under the Configuration section. Open it up with a text editor and adjust the following lines look something like this:
<?php
$conf['mysql_host'] = "localhost"; $conf['mysql_user'] = "adminmail"; $conf['mysql_password'] = "mypassword"; $conf['mysql_database'] = "mail";
?>Note: the 'view_users' is the table that houses the virtual users (different email addresses for different domains).
<?php
$conf['q_mailbox_path'] = "SELECT CONCAT('/home/vmail/', SUBSTRING_INDEX(email,'@',-1), '/', SUBSTRING_INDEX(email,'@',1), '/') as 'path' FROM users WHERE 'email' = '%m'";
?>We are now ready to configure the files on the server. First we must move the autoresponder.php file into the /usr/local/bin. I used an FTP client to do this, however alternatively you could have done the whole process through terminal. This is what the file looks like in the /usr/local/bin in the right directory:

Next you need to give permissions and ownership to the user vmail (same user as your Postfix configuration). In the picture above I have already done this, but the command to do this in a terminal is:
chown vmail:vmail /usr/local/bin/autoresponder.php chmod 755 /usr/local/bin/autoresponder.phpNext create the log file for Goldfish to write into for you to debug with if you ever have problems with the script:
{syntaxhighlighter brush: plain} touch /var/log/goldfish chown vmail:vmail /var/log/goldfish {/syntaxhighlighter}
Now the most important step of configuring Goldfish - giving it a cron job, so it executes on an interval to check for mail that needs an auto-response. The command is:
crontab -u vmail -eNext and empty screen will come up for you (if not, just add another entry, this just means the user 'vmail' has other cron jobs). Add the following:
*/5 * * * * /usr/local/bin/autoresponder.php The number in the line we have just entered is the interval and can be changed depending on how often you wish the script to check if any auto-replies need to be sent out. I chose 5 minutes; however if you wish to change this interval don't forget to change the interval in the /usr/local/bin/autoresponder.php file.
The tutorial that shows how to configure your Goldfish with Round cube can be found here.
Troubleshooting
Check your log
To start troubleshooting why your auto responder is not working, always check the log files first that Goldfish wrote. To do this in terminal, type the following command (and look at the very bottom to see the most recent problems):
nano /etc/var/log/goldfish{/syntaxhighlighter}Database connection errors
Check the settings you set inside of you autoresponder.php file for the database.
Not fetching the subject and the message
Most likely this is because the period you entered in your record ('from' & 'to' fields) is expired. Always check your 'autoresponder' table when testing to make sure Goldfish does not set the 'enabled' field to 0 (this actually disables the autoresponder for that email).
Strange issues with the interval
Chances are that the time interval in your crontab for the user 'vmail' and the interval in your /usr/local/bin/autoresponder.php file are not matching, they need to match in order to work correctly. It can be set in this line of code:
<?php
$conf['cycle'] = 5 * 60;
?>Problem with email disappearing from the /home/vmail/domain_name/user_name/new too fast
If your autoresponder is not auto-replying there are a few things that may be causing this. When I first configured it on my server, it was also not replying. In my case the problem was that the server was moving files out of the /home/vmail/domain_name/user_name/new into the /home/vmail/domain_name/user_name/cur. To fix this I adjusted this line in autoresponder.php (around line 225) to this:
<?php
$paths[] = mysql_result($result, 0, 'path') . 'cur/';
?>