Index: config/main.inc.php.dist
===================================================================
--- config/main.inc.php.dist	(revision 620)
+++ config/main.inc.php.dist	(working copy)
@@ -59,18 +59,22 @@
 
 // use this host for sending mails.
 // to use SSL connection, set ssl://smtp.host.com
-// if left blank, the PHP mail() function is used
+// if left blank, the PHP mail() function is used.
+// Specify an array with 'imap_host'=>'smtp_server' for multiples
 $rcmail_config['smtp_server'] = '';
 
 // SMTP port (default is 25; 465 for SSL)
+// Specify an array with 'smtp_server'=>port for multiples
 $rcmail_config['smtp_port'] = 25;
 
 // SMTP username (if required) if you use %u as the username RoundCube
 // will use the current username for login
+// Specify an array with 'smtp_server'=>'user' for multiples
 $rcmail_config['smtp_user'] = '';
 
 // SMTP password (if required) if you use %p as the password RoundCube
 // will use the current user's password for login
+// Specify an array with 'smtp_server'=>'password' for multiples
 $rcmail_config['smtp_pass'] = '';
 
 // SMTP AUTH type (DIGEST-MD5, CRAM-MD5, LOGIN, PLAIN or empty to use
Index: program/include/rcube_smtp.inc
===================================================================
--- program/include/rcube_smtp.inc	(revision 620)
+++ program/include/rcube_smtp.inc	(working copy)
@@ -53,10 +53,21 @@
   {
   global $SMTP_CONN, $CONFIG;
   $smtp_timeout = null;
-  $smtp_host = $CONFIG['smtp_server'];
-  $smtp_port = is_numeric($CONFIG['smtp_port']) ? $CONFIG['smtp_port'] : 25;
-  $smtp_host_url = parse_url($CONFIG['smtp_server']);
+  $smtp_host = $_SESSION['smtp_server'];
+  $smtp_port = (is_array($CONFIG['smtp_port']) && isset($CONFIG['smtp_port'][$smtp_host]))
+                 ? $CONFIG['smtp_port'][$smtp_host] : 25;
+  $smtp_host_url = parse_url($smtp_host);
   
+  if (is_string($CONFIG['smtp_user']))
+    $smtp_user = $CONFIG['smtp_user'];
+  else if (is_array($CONFIG['smtp_user']) && isset($CONFIG['smtp_user'][$smtp_host]))
+    $smtp_user = $CONFIG['smtp_user'][$smtp_host];
+
+  if (is_string($CONFIG['smtp_pass']))
+    $smtp_pass = $CONFIG['smtp_pass'];
+  else if (is_array($CONFIG['smtp_pass']) && isset($CONFIG['smtp_pass'][$smtp_host]))
+    $smtp_pass = $CONFIG['smtp_pass'][$smtp_host];
+
   // overwrite port
   if ($smtp_host_url['host'] && $smtp_host_url['port'])
     {
@@ -68,7 +79,6 @@
   if ($smtp_host_url['host'] && $smtp_host_url['scheme'])
     $smtp_host = sprintf('%s://%s', $smtp_host_url['scheme'], $smtp_host_url['host']);
 
-
   // create Net_SMTP object and connect to server
   if (!is_object($smtp_conn))
     {
@@ -88,33 +98,28 @@
       $response[] = "Connection failed: ".$result->getMessage();
       return FALSE;
       }
-      
+
     // attempt to authenticate to the SMTP server
-    if ($CONFIG['smtp_user'] && $CONFIG['smtp_pass'])
-      {
-      if (strstr($CONFIG['smtp_user'], '%u'))
-        $smtp_user = str_replace('%u', $_SESSION['username'], $CONFIG['smtp_user']);
-      else
-        $smtp_user = $CONFIG['smtp_user'];
+    if ($smtp_user && $smtp_pass)
+      {      
+      if (strstr($smtp_user, '%u'))
+        $smtp_user = str_replace('%u', $_SESSION['username'], $smtp_user);
 
-      if (strstr($CONFIG['smtp_pass'], '%p'))
-        $smtp_pass = str_replace('%p', decrypt_passwd($_SESSION['password']), $CONFIG['smtp_pass']);
-      else
-        $smtp_pass = $CONFIG['smtp_pass'];
+      if (strstr($smtp_pass, '%p'))
+        $smtp_pass = str_replace('%p', decrypt_passwd($_SESSION['password']), $smtp_pass);
 
       $smtp_auth_type = empty($CONFIG['smtp_auth_type']) ? NULL : $CONFIG['smtp_auth_type'];
       $result = $SMTP_CONN->auth($smtp_user, $smtp_pass, $smtp_auth_type);
-    
+
       if (PEAR::isError($result))
         {
         smtp_reset();
-        $response[] .= "Authentication failure: ".$result->getMessage();
+        $response[] .= "Authentication failure: " . $result->getMessage();
         return FALSE;
         }
       }
     }
 
-
   // prepare message headers as string
   if (is_array($headers))
     {
@@ -144,7 +149,6 @@
     return FALSE;
     }
 
-
   // set From: address
   if (PEAR::isError($SMTP_CONN->mailFrom($from)))
     {
@@ -153,7 +157,6 @@
     return FALSE;
     }
 
-
   // prepare list of recipients
   $recipients = smtp_parse_rfc822($recipients);
   if (PEAR::isError($recipients))
@@ -162,7 +165,6 @@
     return FALSE;
     }
 
-
   // set mail recipients
   foreach ($recipients as $recipient)
     {
@@ -174,7 +176,6 @@
       }
     }
 
-
   // Concatenate headers and body so it can be passed by reference to SMTP_CONN->data
   // so preg_replace in SMTP_CONN->quotedata will store a reference instead of a copy. 
   // We are still forced to make another copy here for a couple ticks so we don't really 
Index: program/include/main.inc
===================================================================
--- program/include/main.inc	(revision 620)
+++ program/include/main.inc	(working copy)
@@ -308,7 +308,7 @@
 
 
 // return correct name for a specific database sequence
-// (used for Postres only)
+// (used for Postgres only)
 function get_sequence_name($sequence)
   {
   global $CONFIG;
@@ -319,7 +319,7 @@
   if (strlen($CONFIG[$config_key]))
     return $CONFIG[$config_key];
   
-  return $table;
+  return $sequence;
   }
 
 
@@ -563,6 +563,16 @@
     $_SESSION['password']  = encrypt_passwd($pass);
     $_SESSION['login_time'] = mktime();
 
+    // If multi-SMTP servers, use correct one
+    // Otherwise, use the general SMTP server
+    // or use phpMail function
+    if (is_array($CONFIG['smtp_server']) && isset($CONFIG['smtp_server'][$host]))
+      $_SESSION['smtp_server'] = $CONFIG['smtp_server'][$host];
+    elseif (is_string($CONFIG['smtp_server']) && !empty($CONFIG['smtp_server']) && $CONFIG['smtp_server'] != '')
+      $_SESSION['smtp_server'] = $CONFIG['smtp_server'];
+    else
+      $_SESSION['smtp_server'] = 'phpMail';
+                                    
     // force reloading complete list of subscribed mailboxes
     rcmail_set_imap_prop();
     $IMAP->clear_cache('mailboxes');
Index: program/steps/mail/sendmail.inc
===================================================================
--- program/steps/mail/sendmail.inc	(revision 620)
+++ program/steps/mail/sendmail.inc	(working copy)
@@ -314,7 +314,7 @@
 if (!$savedraft) {
 
   // send thru SMTP server using custom SMTP library
-  if ($CONFIG['smtp_server'])
+  if ($_SESSION['smtp_server'] != 'phpMail')
     {
     // generate list of recipients
     $a_recipients = array($mailto);
