diff --git a/mimemail.rules.inc b/mimemail.rules.inc
index bbbad51..81bcb55 100644
--- a/mimemail.rules.inc
+++ b/mimemail.rules.inc
@@ -17,6 +17,11 @@ function mimemail_rules_action_info() {
       'label' => t('Send HTML e-mail'),
       'group' => t('System'),
       'parameter' => array(
+        'key' => array(
+          'type' => 'text',
+          'label' => t('Key'),
+          'description' => t('A key to identify the e-mail sent.'),
+        ),
         'to' => array(
           'type' => 'text',
           'label' => t('To'),
@@ -83,6 +88,11 @@ function mimemail_rules_action_info() {
       'label' => t('Send HTML mail to all users of a role'),
       'group' => t('System'),
       'parameter' => array(
+        'key' => array(
+          'type' => 'text',
+          'label' => t('Key'),
+          'description' => t('A key to identify the e-mail sent.'),
+        ),
         'roles' => array(
           'type' => 'list<integer>',
           'label' => t('Roles'),
@@ -159,6 +169,7 @@ function mimemail_rules_action_mail_to_users_of_role_upgrade_map_name($element)
  * Implements hook_rules_action_base_upgrade().
  */
 function mimemail_rules_action_mail_upgrade($element, RulesPlugin $target) {
+  $target->settings['key'] = $element['#settings']['key'];
   $target->settings['from_name'] = $element['#settings']['sender'];
   $target->settings['from_mail'] = $element['#settings']['from'];
   $target->settings['body'] = $element['#settings']['message_html'];
@@ -195,7 +206,7 @@ function mimemail_rules_action_mail_to_users_of_role_upgrade($element, RulesPlug
 /**
  * Action Implementation: Send HTML mail.
  */
-function rules_action_mimemail($to, $cc = NULL, $bcc = NULL, $from_name = NULL, $from_mail = NULL, $reply_to = NULL, $subject, $body, $plaintext = NULL, $attachments = array(), $settings, RulesState $state, RulesPlugin $element) {
+function rules_action_mimemail($key, $to, $cc = NULL, $bcc = NULL, $from_name = NULL, $from_mail = NULL, $reply_to = NULL, $subject, $body, $plaintext = NULL, $attachments = array(), $settings, RulesState $state, RulesPlugin $element) {
   // Set the sender name and from address.
   if (empty($from_mail)) {
     $from = NULL;
@@ -232,17 +243,13 @@ function rules_action_mimemail($to, $cc = NULL, $bcc = NULL, $from_name = NULL,
     'attachments' => $attachments,
   );
 
-  // Set a unique key for this mail.
-  $name = isset($element->root()->name) ? $element->root()->name : 'unnamed';
-  $key = 'rules_action_mimemail_' . $name . '_' . $element->elementId();
-
   drupal_mail('mimemail', $key, $to, $language, $params, $from);
 }
 
 /**
  * Action: Send HTML mail to all users of a specific role group(s).
  */
-function rules_action_mimemail_to_users_of_role($roles, $active, $from_name = NULL, $from_mail = NULL, $subject, $body, $plaintext = NULL, $attachments = array(), $settings, RulesState $state, RulesPlugin $element) {
+function rules_action_mimemail_to_users_of_role($key, $roles, $active, $from_name = NULL, $from_mail = NULL, $subject, $body, $plaintext = NULL, $attachments = array(), $settings, RulesState $state, RulesPlugin $element) {
   // Set the sender name and from address.
   if (empty($from_mail)) {
     $from = NULL;
@@ -283,10 +290,6 @@ function rules_action_mimemail_to_users_of_role($roles, $active, $from_name = NU
     'attachments' => $attachments,
   );
 
-  // Set a unique key for this mail.
-  $name = isset($element->root()->name) ? $element->root()->name : 'unnamed';
-  $key = 'rules_action_mimemail_to_users_of_role_' . $name . '_' . $element->elementId();
-
   $message = array('result' => TRUE);
   foreach ($result as $row) {
     $message = drupal_mail('mimemail', $key, $row->mail, language_default(), $params, $from);
diff --git a/modules/mimemail_action/mimemail_action.module b/modules/mimemail_action/mimemail_action.module
index 65c290e..a594095 100644
--- a/modules/mimemail_action/mimemail_action.module
+++ b/modules/mimemail_action/mimemail_action.module
@@ -45,6 +45,7 @@ function mimemail_send_email_action($entity, $context) {
       'subject' => token_replace($context['subject'], $context),
       'body' => token_replace($context['body'], $context),
     ),
+    'key' => $context['key'],
     'cc' => $context['cc'],
     'bcc' => $context['bcc'],
     'reply-to' => $context['reply-to'],
@@ -52,7 +53,7 @@ function mimemail_send_email_action($entity, $context) {
     'attachments' => $context['attachments'],
   );
 
-  drupal_mail('mimemail', 'action_send_email', $to, $language, $params);
+  drupal_mail('mimemail', $context['key'], $to, $language, $params);
 }
 
 /**
@@ -60,6 +61,7 @@ function mimemail_send_email_action($entity, $context) {
  */
 function mimemail_send_email_action_form($context) {
   $context += array(
+    'key' => '',
     'to' => '',
     'cc' => '',
     'bcc' => '',
@@ -71,6 +73,13 @@ function mimemail_send_email_action_form($context) {
     'attachments' => ''
   );
 
+  $form['key'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Key'),
+    '#default_value' => $context['key'],
+    '#description' => t('A key to identify the e-mail sent.'),
+    '#required' => TRUE,
+  );
   $form['to'] = array(
     '#type' => 'textfield',
     '#title' => t('Recipient'),
@@ -168,6 +177,7 @@ function mimemail_send_email_action_submit($form, $form_state) {
   $form_values = $form_state['values'];
 
   $params = array(
+    'key' => $form_values['key'],
     'to' => $form_values['to'],
     'cc' => $form_values['cc'],
     'bcc' => $form_values['bcc'],
