diff --git a/README.txt b/README.txt
index 903f88e..46d87d6 100644
--- a/README.txt
+++ b/README.txt
@@ -12,9 +12,33 @@ INSTALLATION
      Administer > Site configuration > Mime Mail
 
 USAGE
-  This module may be required by other modules, but is not terribly
-  useful by itself. Once installed, any module can send messages by
-  calling the mimemail() function:
+  This module may be required by other modules, but is not terribly useful by
+  itself. Once installed, any module can send MIME-encoded messages by
+  specifing MimeMailSystem as the responsible mail system for a particular
+  message or all mail sent by one module.
+
+  This can be done through the web by visiting admin/settings/mailsystem
+  or in a program as follows:
+
+  mailsystem_set(array(
+    '{$module}_{$key}' => 'MimeMailSystem', // Just messages with $key sent by $module.
+    '{$module}' => 'MimeMailSystem', // All messages sent by $module.
+  ));
+
+  You can use the following optional parameters to build the e-mail:
+    'plain':
+      Boolean, whether to send messages in plaintext-only (optional, default is FALSE).
+    'plaintext':
+      Plaintext portion of a multipart e-mail (optional).
+    'attachments':
+      Array of arrays with the path or content, name and MIME type of the file (optional).
+    'headers':
+      A keyed array with headers (optional).
+
+  You can set these in $params either before calling drupal_mail() or in hook_mail()
+  and of course hook_mail_alter().
+
+  MIME-encoded messages may also be sent by calling the mimemail() function directly:
 
   $sender      - a user object, text email address or an array with name, mail
   $recipient   - a user object, text email address or an array with name, mail
diff --git a/includes/mimemail.mail.inc b/includes/mimemail.mail.inc
new file mode 100644
index 0000000..f71ffcf
--- /dev/null
+++ b/includes/mimemail.mail.inc
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * @file
+ * Mime Mail implementations of MailSystemInterface.
+ */
+
+/**
+ * Modify the Drupal mail system to send HTML emails.
+ */
+class MimeMailSystem implements MailSystemInterface {
+  /**
+   * Concatenate and wrap the e-mail body for HTML mails.
+   *
+   * @param array $message
+   *   A message array, as described in hook_mail_alter() with optional
+   *   parameters described in mimemail_prepare_message().
+   *
+   * @return array
+   *   The formatted $message.
+   */
+  public function format(array $message) {
+    if (is_array($message['body'])) {
+      $message['body'] = implode("\n\n", $message['body']);
+    }
+
+    if (preg_match('/plain/', $message['headers']['Content-Type'])) {
+      $message['body'] = check_markup($message['body'], variable_get('mimemail_format', variable_get('filter_default_format', FILTER_DEFAULT_FORMAT)));
+    }
+
+    $engine = variable_get('mimemail_engine', 'mimemail');
+    $mailengine = $engine . '_mailengine';
+    $engine_prepare_message = $engine . '_prepare_message';
+
+    $sender = $message['from'];
+    $recipient = $message['to'];
+    $subject = $message['subject'];
+    $body = $message['body'];
+    $headers = $message['headers'];
+    $plaintext = NULL; // Let the engine decide if to send as plaintext only.
+    $text = NULL; // Let the engine prep the plain text copy.
+    $attachments = !empty($message['params']['attachments']) ? $message['params']['attachments'] : array();
+    $mailkey = $message['id'];
+
+    if (function_exists($engine_prepare_message)) {
+      $message = $engine_prepare_message($sender, $recipient, $subject, $body, $plaintext, $headers, $text, $attachments, $mailkey);
+    }
+    else {
+      $message = mimemail_prepare_message($sender, $recipient, $subject, $body, $plaintext, $headers, $text, $attachments, $mailkey);
+    }
+
+    return $message;
+  }
+
+  /**
+   * Send an HTML e-mail message, using Drupal variables and default settings.
+   *
+   * @param array $message
+   *   A message array, as described in hook_mail_alter() with optional
+   *   parameters described in mimemail_prepare_message().
+   *
+   * @return boolean
+   *   TRUE if the mail was successfully accepted, otherwise FALSE.
+   */
+  public function mail(array $message) {
+    $engine = variable_get('mimemail_engine', 'mimemail');
+    $mailengine = $engine . '_mailengine';
+
+    if (!$engine || !function_exists($mailengine)) {
+      return FALSE;
+    }
+
+    return $mailengine('send', $message);
+  }
+}
diff --git a/mimemail.info b/mimemail.info
index 89bc565..2ab10d7 100644
--- a/mimemail.info
+++ b/mimemail.info
@@ -2,6 +2,11 @@ name = Mime Mail
 description = Allows to send HTML e-mail with embedded images and attachments.
 package = Mail
 core = 6.x
+dependencies[] = mailsystem
+dependencies[] = autoload
+
+; Register the MimeMailSystem class for autoload.
+files[] = includes/mimemail.mail.inc
 
 ; Information added by Drupal.org packaging script on 2015-01-25
 version = "6.x-1.4+1-dev"
diff --git a/mimemail.install b/mimemail.install
index 20c76e6..0cfd1c1 100644
--- a/mimemail.install
+++ b/mimemail.install
@@ -22,14 +22,59 @@ function mimemail_requirements($phase) {
       'severity' => REQUIREMENT_ERROR
     );
   }
-
+  // Require mailsystem module, or disable Mimemail and returns
+  // an informative error message.
+  if ($phase === 'install' || module_exists('mailsystem')) {
+    return $requirements;
+  }
+  $args = array(
+    '!mailsystem' => url('http://drupal.org/project/mailsystem'),
+    '%mailsystem' => 'Mail System',
+    '!mimemail' => url('http://drupal.org/project/mimemail'),
+    '%mimemail' => 'Mime Mail',
+  );
+  if ( module_enable(array('mailsystem'))
+    && module_load_include('module', 'mailsystem')
+  ) {
+    drupal_set_message(
+      $t('The %mailsystem module has been enabled because the %mimemail module now requires it.', $args)
+    );
+    return $requirements;
+  }
+  $requirements['mimemail_mailsystem'] = array(
+    'title' => $t('%mailsystem module', $args),
+    'value' => $t('Not installed'),
+    'description' => $t(
+      'The <a href="!smtp">%mimemail</a> module dependencies have changed.  Please download and install the required <a href="!mailsystem">%mailsystem</a> module, then re-enable the <a href="!mimemail">%mimemail</a> module.', $args
+    ),
+    'severity' => REQUIREMENT_ERROR,
+  );
   return $requirements;
 }
 
 /**
- * Implements hook_install().
+ * Implements hook_enable().
  */
-function mimemail_install() {
+function mimemail_enable() {
+  module_load_include('module', 'mailsystem');
+  mailsystem_set(
+    array(
+      mailsystem_default_id() => 'MimeMailSystem',
+      'mimemail' => 'MimeMailSystem',
+    )
+  );
+
+  // Make sure the class include file gets listed in the registry.
+  autoload_registry_update();
+  // Load mailsystem if necessary.
+  module_load_include('module', 'mailsystem');
+  // Install the MimeMail into the mailsystem and set it as the default.
+  mailsystem_set(array(
+    mailsystem_default_id() => 'MimeMailSystem',
+    'mimemail' => 'MimeMailSystem',
+  ));
+  mailsystem_get_classes(TRUE);
+
   $perm = explode(', ', db_result(db_query("SELECT perm FROM {permission} WHERE rid=%d", DRUPAL_AUTHENTICATED_RID)));
   $perm = implode(', ', array_merge($perm, array('edit mimemail user settings')));
   $record = array('rid' => DRUPAL_AUTHENTICATED_RID, 'perm' => $perm);
@@ -40,6 +85,7 @@ function mimemail_install() {
  * Implements hook_disable().
  */
 function mimemail_disable() {
+  mailsystem_clear(array('mimemail' => 'MimeMailSystem'));
   if (strpos(variable_get('smtp_library', ''), 'mimemail') !== FALSE) {
     variable_del('smtp_library');
   }
@@ -91,3 +137,15 @@ function mimemail_update_6101() {
 
   return $ret;
 }
+
+/**
+ * Install the mailsystem set for MimeMail.
+ */
+function mimemail_update_6102() {
+  module_load_include('module', 'mailsystem');
+  mailsystem_set(
+    array(
+      'mimemail' => 'MimeMailSystem',
+    )
+  );
+}
diff --git a/mimemail.module b/mimemail.module
index 060ff76..911962e 100644
--- a/mimemail.module
+++ b/mimemail.module
@@ -192,8 +192,11 @@ function mimemail_prepare_message($sender, $recipient, $subject, $body, $plainte
       }
     }
   }
+
+  // Removing newline character introduced by _drupal_wrap_mail_line();
   $subject = str_replace(array(" \n", "\n"), '', trim(drupal_html_to_text($subject)));
   $body = theme(array('mimemail_message__'. $mailkey, 'mimemail_message'), $subject, $body, $mailkey, $recipient);
+
   foreach (module_implements('mail_post_process') as $module) {
     $function = $module .'_mail_post_process';
     $function($body, $mailkey);
@@ -205,10 +208,10 @@ function mimemail_prepare_message($sender, $recipient, $subject, $body, $plainte
   $mail      = mimemail_html_body($body, $subject, $plaintext, $text, $attachments);
   $headers   = array_merge($headers, $mail['headers']);
   $message   = array(
-    'address' => mimemail_address($recipient),
+    'to' => mimemail_address($recipient),
     'subject' => $subject,
     'body'    => $mail['body'],
-    'sender'  => $sender,
+    'from'  => $sender,
     'headers' => mimemail_headers($headers, $sender),
   );
 
@@ -340,10 +343,10 @@ function mimemail_mailengine($op, $message = array()) {
 
   // Default values.
   $message = array_merge(array(
-      'address' => '',
+      'to' => '',
       'subject' => '',
       'body' => '',
-      'sender' => '',
+      'from' => '',
       'headers' => '',
       ), $message);
 
@@ -377,7 +380,7 @@ function mimemail_mailengine($op, $message = array()) {
       }
 
       $status = TRUE;
-      foreach ($message['address'] as $to) {
+      foreach ($message['to'] as $to) {
         $subject = $message['subject'];
         $body = $message['body'];
         $headers = mimemail_rfc_headers($message['headers']);
@@ -435,7 +438,7 @@ if (strpos(variable_get('smtp_library', ''), 'mimemail') !== FALSE
     $attachments = isset($message['attachments']) ? $message['attachments'] : array();
     $mailkey = isset($message['id']) ? $message['id'] : '';
 
-    $message = mimemail($from, $to, $subject, $body, $plaintext, $headers, $text, $attachments, $mailkey); 
+    $message = mimemail($from, $to, $subject, $body, $plaintext, $headers, $text, $attachments, $mailkey);
 
     return $message['result'];
   }
diff --git a/theme/mimemail.theme.inc b/theme/mimemail.theme.inc
index 981cc67..bf9cf6a 100644
--- a/theme/mimemail.theme.inc
+++ b/theme/mimemail.theme.inc
@@ -9,6 +9,7 @@ function mimemail_theme_theme() {
   return array(
     'mimemail_message' => array(
       'arguments' => array('subject' => NULL, 'body' => NULL, 'mailkey' => NULL, 'recipient' => NULL),
+      'mail theme' => TRUE,
       'template' => 'mimemail-message',
       'pattern' => 'mimemail_message__',
       'file' => 'mimemail.theme.inc',
@@ -27,7 +28,7 @@ function mimemail_theme_theme() {
  * - $recipient: An email address or user object who is receiving the message.
  */
 function template_preprocess_mimemail_message(&$variables) {
-  $theme = variable_get('theme_default', NULL);
+  $theme = mailsystem_get_mail_theme();
 
   // Fetch the theme for the current domain.
   if (module_exists('domain_theme')) {
@@ -40,35 +41,36 @@ function template_preprocess_mimemail_message(&$variables) {
     }
   }
 
-  $themepath = (function_exists('path_to_subtheme')) ? path_to_subtheme() : drupal_get_path('theme', $theme);
+  $themepath = drupal_get_path('theme', $theme);
 
   $sitestyle = variable_get('mimemail_sitestyle', 1);
-  $mailstyles = file_scan_directory($themepath, '^mail\.css*$');
-
-  $css_all = drupal_add_css();
-  $css_files_mail = $css_files_screen = array();
-  foreach ($css_all as $media => $types) {
-    foreach ($types as $type => $file) {
-      // Gather and always include CSS files with 'email' media.
-      if ($media == 'email') {
-        $css_files_mail[$media][$type] = $file;
-      }
-      // Gather and include other site style sheets if enabled.
-      elseif ($type == 'theme' && ($media == 'all' || $media == 'screen')) {
-        $css_files_screen[$media][$type] = $file;
-      }
-    }
-  }
-  $styles = _mimemail_css_file_paths($css_files_mail);
+  $mailstyles = file_scan_directory($themepath, '^mail\.css*$', array('.', '..', 'CVS'), 0, TRUE);
 
   // Check recursively for the existence of a mail.css file in the default theme folder.
   if (!empty($mailstyles)) {
     foreach ($mailstyles as $mailstyle) {
-      array_push($styles, $mailstyle->filename);
+      $styles[] = $mailstyle->filename;
     }
   }
   // When no mail.css was found, include site style sheets if enabled.
   elseif ($sitestyle) {
+
+    $css_all = drupal_add_css();
+    $css_files_mail = $css_files_screen = array();
+    foreach ($css_all as $media => $types) {
+      foreach ($types as $type => $file) {
+        // Gather and always include CSS files with 'email' media.
+        if ($media == 'email') {
+          $css_files_mail[$media][$type] = $file;
+        }
+        // Gather and include other site style sheets if enabled.
+        elseif ($type == 'theme' && ($media == 'all' || $media == 'screen')) {
+          $css_files_screen[$media][$type] = $file;
+        }
+      }
+    }
+    $styles = _mimemail_css_file_paths($css_files_mail);
+
     // Grab local.css if it exists (support for Fusion based themes).
     $local = $themepath . '/css/local.css';
     if (@file_exists($local)) {
@@ -77,11 +79,13 @@ function template_preprocess_mimemail_message(&$variables) {
     $styles = array_merge($styles, _mimemail_css_file_paths($css_files_screen));
   }
 
-  // Process each style sheet.
   $css = '';
-  foreach ($styles as $style) {
-    if (!empty($style) && @file_exists($style)) {
-      $css .= drupal_load_stylesheet($style, TRUE);
+  if (isset($styles)) {
+    // Process each style sheet.
+    foreach ($styles as $style) {
+      if (!empty($style) && @file_exists($style)) {
+        $css .= drupal_load_stylesheet($style, TRUE);
+      }
     }
   }
 
@@ -89,6 +93,9 @@ function template_preprocess_mimemail_message(&$variables) {
   $css = wordwrap($css, 700);
   $variables['css'] = $css;
 
+  // Set template alternatives.
+  $variables['theme_hook_suggestions'][] = 'mimemail_message__' . str_replace('-', '_', $variables['mailkey']);
+
    // Process mailkey to be a proper CSS class.
   $variables['mailkey'] = 'mail-'. str_replace('_', '-', $variables['mailkey']);
 }
