diff --git a/includes/mimemail.admin.inc b/includes/mimemail.admin.inc
index d7ad8b8..57171ac 100644
--- a/includes/mimemail.admin.inc
+++ b/includes/mimemail.admin.inc
@@ -78,6 +78,40 @@ function mimemail_admin_settings() {
     '#attributes' => array('class' => array('filter-list')),
   );
 
+  // Generate a list of options of which theme use to render the email
+  // * current - Theme currently used by the user who runs drupal_mail
+  // * default - Default theme, obtained via variable theme_default
+  // * domain - Theme obtained via domain_theme module
+  // * plus all the rest of active themes
+  $theme_options = array();
+  $theme_options['current'] = t('Current theme');
+  $theme_options['default'] = t('Default theme');
+  if (module_exists('domain_theme')) {
+    $theme_options['domain'] = t('Domain theme');
+  }
+  $theme_list = list_themes();
+  foreach ($theme_list as $position => $item) {
+    if ($item->status == 1) {
+      $theme_options[$position] = $item->info['name'];
+    }
+  }
+  $theme_description = '<p>' . t('Select the theme that wil be used to render the email:') . '</p>';
+  $theme_description .= '<ul>';
+  $theme_description .= '<li>' . t('Current theme: Currently used by the user who runs drupal_mail.') . '</li>';
+  $theme_description .= '<li>' . t('Default theme: Obtained via variable theme_default.') . '</li>';
+  if (module_exists('domain_theme')) {
+    $theme_description .= '<li>' . t('Domain theme: Obtained via domain_theme module.') . '</li>';
+  }
+  $theme_description .= '<li>' . t('Any active theme.') . '</li>';
+  $theme_description .= '</ul>';
+  $form['mimemail']['mimemail_theme'] = array(
+    '#type' => 'select',
+    '#title' => t('Theme to render emails'),
+    '#description' => $theme_description,
+    '#options' => $theme_options,
+    '#default_value' => variable_get('mimemail_theme', 'current'),
+  );
+
   $form['mimemail']['advanced'] = array(
     '#type' => 'fieldset',
     '#title' => t('Advanced settings'),
@@ -137,5 +171,17 @@ function mimemail_admin_settings() {
     drupal_set_message(t('Please choose a mail engine.'), 'error');
   }
 
-  return system_settings_form($form);
+  $form = system_settings_form($form);
+  // We need to run mimemail_admin_settings_submit after variable set
+  $form['#submit'][] = 'mimemail_admin_settings_submit';
+  return $form;
 }
+
+
+/**
+ * Submit function of mimemail_admin_settings form.
+ * Rebuilds theme registry to make changes needed by theme rendering.
+ */
+function mimemail_admin_settings_submit($form, &$form_state) {
+  drupal_theme_rebuild();
+}
\ No newline at end of file
diff --git a/includes/mimemail.rules.inc b/includes/mimemail.rules.inc
index 4b3fe2d..d97e2cb 100644
--- a/includes/mimemail.rules.inc
+++ b/includes/mimemail.rules.inc
@@ -76,7 +76,7 @@ function rules_action_mimemail_to_users_of_role($roles, $from_name = NULL, $from
   else {
     $rids = implode(',', $roles);
     // Avoid sending emails to members of two or more target role groups.
-    $result = db_query('SELECT DISTINCT u.mail FROM {users} u INNER JOIN {users_roles} r ON u.uid = r.uid WHERE r.rid IN ('. $rids .')');
+    $result = db_query('SELECT DISTINCT u.mail FROM {users} u INNER JOIN {users_roles} r ON u.uid = r.uid WHERE r.rid IN (' . $rids . ')');
   }
 
   $params = array(
diff --git a/mimemail.module b/mimemail.module
index 9b4924b..857ce72 100644
--- a/mimemail.module
+++ b/mimemail.module
@@ -449,3 +449,108 @@ function mimemail_prepare_message($message) {
 
   return $message;
 }
+
+/**
+* Implements hook_theme_registry_alter().
+*/
+function mimemail_theme_registry_alter(&$theme_registry) {
+  global $theme_key;
+  static $executed = array();
+
+  // Preventing double execution
+  if (isset($executed[$theme_key])) {
+    return;
+  }
+
+  $executed[$theme_key] = TRUE;
+  foreach ($theme_registry as $position => $item) {
+    if ($position == 'mimemail_message') {
+      $mimemail_theme = _mimemail_get_theme();
+      // We don't have to change anything in case the render theme is the same as the current render
+      if ($mimemail_theme != $theme_key) {
+        $themes = list_themes();
+
+        // Getting render theme
+        $theme = isset($themes[$mimemail_theme]) ? clone $themes[$mimemail_theme] : NULL;
+        if ($theme != NULL) {
+          // Stablishing variables for further process
+          $base_theme = array();
+          if (isset($theme->base_themes)) {
+            foreach (array_keys($theme->base_themes) as $base) {
+              $base_theme[$base] = clone $themes[$base];
+            }
+          }
+          if (isset($theme->base_theme) && !isset($base_theme[$theme->base_theme])) {
+            $base_theme[$theme->base_theme] = clone $themes[$theme->base_theme];
+          }
+          $theme_engine = isset($theme->engine) ? $theme->engine : NULL;
+
+          // We have to include template files to let _theme_load_registry add preprocess funcions
+          // it uses function_exists.
+          // @todo - It just currently work with phptemplate because we don't have a way to know
+          // which files to include depending on the engine.
+          // We could have used _drupal_theme_initialize disabling stylesheets and scripts, but
+          // _drupal_theme_initialize changes global $theme_path so it will be necessary to
+          // replace theme->filename previously and then put again the original. As later
+          // we are going to add includes manually and it breaks other engines compability
+          // it would be silly not to do this this ways.
+          include_once(drupal_get_path('theme', $theme->name) . '/template.php');
+          foreach ($base_theme as $base) {
+            include_once(drupal_get_path('theme', $base->name) . '/template.php');
+          }
+          $cache = _theme_load_registry($theme, $base_theme, $theme_engine);
+
+          if (isset($cache[$position])) {
+            // We need to include the template.php of the theme and the base themes
+            // @todo - It just currently work with phptemplate because we don't have a way to know
+            // which files to include depending on the engine.
+            $cache[$position]['includes'][] = drupal_get_path('theme', $theme->name) . '/template.php';
+            foreach ($base_theme as $base) {
+              $cache[$position]['includes'][] = drupal_get_path('theme', $base->name) . '/template.php';
+            }
+
+            // Changing current registry for the new record
+            $theme_registry[$position] = $cache[$position];
+          }
+        }
+      }
+    }
+  }
+}
+
+
+/**
+ * Retrieves the theme key configured in admin/config/system/mimemail
+ * used to render emails.
+ * @todo It would be an improvement to add some kind of hook to let other
+ * modules alter this behaviour.
+ * @return key of the theme configured to render emails.
+ */
+function _mimemail_get_theme() {
+  global $theme_key;
+
+  $theme = variable_get('mimemail_theme', 'current');
+  switch ($theme) {
+    case 'default':
+      $theme = variable_get('theme_default', NULL);
+      break;
+    case 'current':
+      $theme = $theme_key;
+      break;
+    case 'domain_theme':
+      // Fetch the theme for the current domain.
+      if (module_exists('domain_theme')) {
+        // Assign the selected theme, based on the active domain.
+        global $_domain;
+        $domain_theme = domain_theme_lookup($_domain['domain_id']);
+        // The above returns -1 on failure.
+        if ($domain_theme != -1) {
+          return $domain_theme['theme'];
+        }
+      }
+      $theme = $theme_key;
+      break;
+  }
+
+  return $theme;
+}
\ No newline at end of file
diff --git a/theme/mimemail.theme.inc b/theme/mimemail.theme.inc
index 7285f51..d29e6f5 100644
--- a/theme/mimemail.theme.inc
+++ b/theme/mimemail.theme.inc
@@ -4,7 +4,7 @@
  * @file
  * The theme system, which controls the output of the messages.
  */
- 
+
 function mimemail_theme_theme() {
   $path = drupal_get_path('module', 'mimemail') . '/theme';
 
@@ -31,18 +31,7 @@ function mimemail_theme_theme() {
  * @see theme/mimemail-message.tpl.php for additional variables.
  */
 function template_preprocess_mimemail_message(&$variables) {
-  $theme = variable_get('theme_default', NULL);
-
-  // Fetch the theme for the current domain.
-  if (module_exists('domain_theme')) {
-    // Assign the selected theme, based on the active domain.
-    global $_domain;
-    $domain_theme = domain_theme_lookup($_domain['domain_id']);
-    // The above returns -1 on failure.
-    if ($domain_theme != -1) {
-      $theme = $domain_theme['theme'];
-    }
-  }
+  $theme = _mimemail_get_theme();
 
   $themepath = drupal_get_path('theme', $theme);
 
