Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.86
diff -u -r1.86 system.admin.inc
--- modules/system/system.admin.inc	30 Aug 2008 09:49:43 -0000	1.86
+++ modules/system/system.admin.inc	6 Sep 2008 05:16:39 -0000
@@ -1210,13 +1210,6 @@
     '#description' => t('The name of this website.'),
     '#required' => TRUE
   );
-  $form['site_mail'] = array(
-    '#type' => 'textfield',
-    '#title' => t('E-mail address'),
-    '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
-    '#description' => t("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"),
-    '#required' => TRUE,
-  );
   $form['site_slogan'] = array(
     '#type' => 'textfield',
     '#title' => t('Slogan'),
@@ -1703,6 +1696,37 @@
 }
 
 /**
+ * Form builder; Configure how the site sends e-mails.
+ * 
+ * @ingroup forms
+ * @see system_settings_form()
+ */
+function system_mail_settings() {
+  $form['site_mail'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Address'),
+    '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
+    '#description' => t("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"),
+    '#required' => TRUE,
+  );
+  
+  $mailengines = array();
+  foreach (module_implements('mailengine', TRUE) as $module) {
+    $mailengines[$module] = module_invoke($module, 'mailengine', 'info');
+  }
+  $form['mail_engine'] = array(
+    '#type' => 'radios',
+    '#title' => t('Engine'),
+    '#description' => t('The e-mail engine to use for sending mails from your site.'),
+    '#default_value' => variable_get('mail_engine', 'system'),
+    '#options' => $mailengines,
+    '#required' => TRUE,
+  );
+
+  return system_settings_form($form);
+}
+
+/**
  * Form builder; Configure the site's maintenance status.
  *
  * @ingroup forms
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.616
diff -u -r1.616 system.module
--- modules/system/system.module	5 Sep 2008 09:29:06 -0000	1.616
+++ modules/system/system.module	6 Sep 2008 05:16:39 -0000
@@ -97,6 +97,8 @@
       return t('An advanced action offers additional configuration options which may be filled out below. Changing the <em>Description</em> field is recommended, in order to better identify the precise action taking place. This description will be displayed in modules such as the trigger module when assigning actions to system events, so it is best if it is as descriptive as possible (for example, "Send e-mail to Moderation Team" rather than simply "Send e-mail").');
     case 'admin/settings/ip-blocking':
       return '<p>' . t('IP addresses listed here are blocked from your site before any modules are loaded. You may add IP addresses to the list, or delete existing entries.') . '</p>';
+    case 'admin/settings/mail':
+      return '<p>' . t('Configure how e-mails are sent from your site.') . '</p>';
     case 'admin/reports/status':
       return '<p>' . t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on drupal.org's support forums and project issue queues.") . '</p>';
   }
@@ -589,6 +591,13 @@
     'page arguments' => array('system_site_maintenance_settings'),
     'access arguments' => array('administer site configuration'),
   );
+  $items['admin/settings/mail'] = array(
+    'title' => 'Mail',
+    'description' => 'Configure how the site sends e-mails.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('system_mail_settings'),
+    'access arguments' => array('administer site configuration'),
+  );
   $items['admin/settings/clean-urls'] = array(
     'title' => 'Clean URLs',
     'description' => 'Enable or disable clean URLs for your site.',
@@ -1876,6 +1885,39 @@
 }
 
 /**
+ * Implementation of hook_mailengine().
+ * 
+ * Delivers messages for drupal_mail() using PHP's mail(). More information in the
+ * <a href="http://php.net/manual/en/function.mail.php">PHP function reference
+ * for mail()</a>. 
+ */
+function system_mailengine($op, $message = NULL) {
+  switch ($op) {
+    case 'info':
+      return t('Mail');
+    break;
+    case 'send':
+      if (is_array($message)) {
+        $mimeheaders = array();
+        foreach ($message['headers'] as $name => $value) {
+          $mimeheaders[] = $name . ': ' . mime_header_encode($value);
+        }
+        return mail(
+          $message['to'],
+          mime_header_encode($message['subject']),
+          // Note: e-mail uses CRLF for line-endings, but PHP's API requires LF.
+          // They will appear correctly in the actual e-mail that is sent.
+          str_replace("\r", '', $message['body']),
+          // For headers, PHP's API suggests that we use CRLF normally,
+          // but some MTAs incorrecly replace LF with CRLF. See #234403.
+          join("\n", $mimeheaders)
+        );
+      }
+    break;
+  }
+}
+
+/**
  * Implementation of hook_mail().
  */
 function system_mail($key, &$message, $params) {
Index: includes/mail.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/mail.inc,v
retrieving revision 1.14
diff -u -r1.14 mail.inc
--- includes/mail.inc	19 May 2008 19:25:24 -0000	1.14
+++ includes/mail.inc	6 Sep 2008 05:16:39 -0000
@@ -141,9 +141,7 @@
 
 /**
  * Send an e-mail message, using Drupal variables and default settings.
- * More information in the <a href="http://php.net/manual/en/function.mail.php">
- * PHP function reference for mail()</a>. See drupal_mail() for information on
- * how $message is composed.
+ * See drupal_mail() for information on how $message is composed.
  *
  * @param $message
  *  Message array with at least the following elements:
@@ -169,29 +167,11 @@
  * @return
  *   Returns TRUE if the mail was successfully accepted for delivery,
  *   FALSE otherwise.
+ * @see system_mailengine()
  */
 function drupal_mail_send($message) {
-  // Allow for a custom mail backend.
-  if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
-    include_once './' . variable_get('smtp_library', '');
-    return drupal_mail_wrapper($message);
-  }
-  else {
-    $mimeheaders = array();
-    foreach ($message['headers'] as $name => $value) {
-      $mimeheaders[] = $name . ': ' . mime_header_encode($value);
-    }
-    return mail(
-      $message['to'],
-      mime_header_encode($message['subject']),
-      // Note: e-mail uses CRLF for line-endings, but PHP's API requires LF.
-      // They will appear correctly in the actual e-mail that is sent.
-      str_replace("\r", '', $message['body']),
-      // For headers, PHP's API suggests that we use CRLF normally,
-      // but some MTAs incorrecly replace LF with CRLF. See #234403.
-      join("\n", $mimeheaders)
-    );
-  }
+  $engine = variable_get('mail_engine', 'system') .'_mailengine';
+  return $engine('send', $message);
 }
 
 /**
