Roundcube autoresponder (Goldfish & Autoreply plugin)


I wrote a tutorial recently explaining on how to configure Goldfish to work with your Postfix on a Linux server. When I finished doing the installation of my autoresponder, I quickly realized that I would need some kind of interface to let users add, change and enable/disable the auto reply messages. On our dedicated server we use Roundcube, so I realized that a plugin was required. I coded my first plugin for Roundcube to allow the port of Goldfish, its called "Autoreply". This tutorial will show you how to set up both of them!

Before beginning, lets go over the the requirements for this to work correctly. Here they are:

  • Postfix
  • Courier
  • MySQL database to house virtual users/domains
  • Roundcube (that supports plugins - early versions did not have this support!)
  • Working version of Goldfish autoresponder

First thing we will need to do is download the source code for both the modified version of Goldfish and the Roundcube Autoreply plugin here or at the bottom of the page.

Next we must modify the 'autoresponder' table in your database to add an extra field. The field we are going to be inserting is called 'force_enabled'. The reason we add this field is because the plugin has the option to force the autoresponder to stop sending emails even if the date falls in-between the 'from' and 'to' dates. However it will not send anything if the current date does not fall in this interval. Here is the SQL code you need to enter for your 'autoresponder' table:

ALTER TABLE autoresponder ADD 'force_enabled' tinyint(4) NOT NULL default '0' AFTER enabled;

You can add this through your terminal using the following commands:

mysql -u root -p

Enter your password, and then select the database with the following command:

USE mail;

This could have also been done through PHPMyAdmin like the following picture:

Paste SQL code in

The structure of your table should look something like this:

View the table structure

Once we have created the extra column for our plugin, we can proceed to making the adjustments to the Goldfish script. The changes we are going to make are very minimal, but required for this to work! Download the autoresponder.php script (should be on your server under the /usr/local/bin/ directory).

Once you have that file, open it with a text editor and adjust the following like to look like this:

<?php
$conf
['q_forwardings'] = "SELECT * FROM 'autoresponder' WHERE 'enabled' = 1 AND 'force_enabled' = 1;"; // MODIFIED!
?>

The next change we are making is so the auto-replier will automatically start regardless if you put the 'from' date not on the same day as today. Find the line and make the changes as follows:

<?php
$conf
['q_enable_forwarding'] = "UPDATE 'autoresponder' SET 'enabled' = 1 WHERE 'from' >= CURDATE();"; // MODIFIED!
?>

After these changes have been made you can re-upload your autoresponder.php script into the correct directory on your server. After this has been uploaded we can proceed to install the interface for this autoresponder in Roundcube. Start by modifying the config.inc.php. Check the queries and make sure they correspond to your database.

The dsn variable only needs to be changed if you do not want to use the default database connection that has already been established for Roundcube. After checking the config file, and adjusting it if required, we can proceed to move the plugin into the plugins/ directory. In my case Roundcube is installed in /var/lib/roundcube.

Move the plugin into the correct directory

After moving it into the plugins directory, we have to enable it, so Roundcube knows to use that plugin. Find the main.inc.php file inside of the config/ directory in Roundcube root. Download it and adjust it with a text editor, on this line change it to:

<?php
// Plugins $rcmail_config['plugins'] = array('autoreply');
?>

This will enable the plugin for use. After you login to your email box navigate to the setting button in the top right:

Settings button top right

Then click on the 'Auto Reply' tab.

Click the auto reply tab

Here you can enter the auto-response for the email you are logged in with and enable it and disable it.

Edit the auto reply



Categories: Linux, PHP, Programming, Server

Comments