Skip to content

Instantly share code, notes, and snippets.

@kimbtech
Last active September 3, 2022 13:13
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimbtech/b6b08f1778420766ee1a2d24117d4871 to your computer and use it in GitHub Desktop.
Save kimbtech/b6b08f1778420766ee1a2d24117d4871 to your computer and use it in GitHub Desktop.
Roundcube multiple SMTP Server plugin for setups having multiple IMAP Server.

This plugin is not needed for versions >= 1.5 of roundcube, as the functionality was added by the developers!

Roundcube allows to access multiple IMAP Server, but all mails have to be send over the same SMTP server. This plugin allows to add multiple SMTP Server (one per IMAP Server) to Roundcube.

// normal declaration of multiple IMAP Server
$config['default_host'] = array(
		'ssl://imap.example.de' => '.de',
		'ssl://mx.example.com' => '.com'
	);

// normal SMTP declaration
$config['smtp_server'] = 'tls://smtp.example.de' // unable to add the SMTP Server for mx.example.com

// new SMTP declaration using the plugin
$config['smtp_server'] = array(
	'imap.example.de' => 'tls://smtp.example.de',
	'mx.example.com' => 'ssl://mx.example.de'
	// IMAP Hostname => SMTP Hostname
	//	(if IMAP Hostname is not in list, we use first SMTP Server)
);

//	and activate the plugin by adding to:
$config['plugins'] = array( ....., 'multi_smtp');

Install

Place the file multi_smtp.php in your installation at /plugins/multi_smtp/multi_smtp.php, edit the config.inc.php.

<?php
class multi_smtp extends rcube_plugin {
public $task = 'mail';
function init(){
if ( version_compare( RCMAIL_VERSION, '1.5', '<') ){ // plugin only needed until version 1.4.x
$this->add_hook('smtp_connect', array($this, 'correct_smtp_server'));
}
}
function correct_smtp_server( $data ){
$imap_server = $_SESSION['storage_host'];
$data['smtp_server'] = isset($data['smtp_server'][$imap_server]) ? $data['smtp_server'][$imap_server] : array_values($data['smtp_server'])[0];
//print_r($data);
return $data;
}
}
?>
@kimbtech
Copy link
Author

Hi,
I just took a look the error and I think this plugin is not needed any more, as the developers of roundcube added the functionality in roundcube itself starting with version 1.5.0 of roundcube (added here https://github.com/roundcube/roundcubemail/blob/1.5.0/program/lib/Roundcube/rcube_smtp.php#L60).

So just delete the folder plugins/multi_smtp and remove multi_smtp from $config['plugins'] if you are on version 1.5.0 or higher.

Hope this helps

@N0ury
Copy link

N0ury commented Nov 25, 2021

@kimbtech thanks for this info.
I'm using 1.5.0
I've just tried and it works fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment