I had to configure webmail service with Roundcube which would allow connecting multi mail servers o one platform. Every mail server had it’s own Roundcube instance already, but idea was, that only one installation can handle all mail servers.
I found out, that this can be done pretty symple with some php in roundcube configuration.
Open your roundcube configuration file, for example:
vi /var/www/roundcube/config/config.inc.php
Fetch correct hostname for specific webmail instance in php variable.
$host = $_SERVER['SERVER_NAME'];
Then you should create switch statement that will be able to manage correct database connection and host for specific server name – mail service. You can also have different types of database. For example mysql and postgres.
switch ($host) { case "webmail1.domain.com":
$config['db_dsnw'] = 'mysql://rcdb1:somepass@1.1.1.1/roundcubemail';
$config['default_host'] = "mail1.domain.com";
break;
case "webmail2.domain.com":
$config['db_dsnw'] = 'pgsql://rcdb2:somepass2@2.2.2.2/roundcube';
$config['default_host'] = "ssl://mail2.domain.com";
break;
case "webmail3.domain.com":
$config['db_dsnw'] = 'mysql://rcdb4:somepass3@3.3.3.3/rc_db';
$config['default_host'] = "ssl://mail3.domain.com";
break;
}
Idea is, that when user will type url webmail1.domain.com, this hostname will be saved in $host. Switch statement will then use proper database and hostname for that specific hostname. Also, default_host should be defined so that correct hostname for mail server will be set.
I tried this on webmail instance with 4 different mail servers, with different database types also and it works.
[kofi]