It would be nice if we could add arbitrary mail headers to e-mails send out by the "Send a mail to an arbitrary mail address", "Send a mail to a user" and "Send a mail to all users of a role" actions, right from the action configuration UI. I'm thinking especially about the "Auto-Submitted" header (http://tools.ietf.org/html/rfc3834) but probably there are others that would be useful.

Comments

trevorbradley’s picture

Component: Provided module integration » Rules Engine

I'd like this as well. I just found webform's function:
function theme_webform_mail_headers($node, $submission, $email) {
which allows you to add cc headers, and any other headers you might want. I'm hunting for the equivalent in Rules.

mitchell’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev

Moving to 7.x.

trevorbradley’s picture

Searching for solutions for a completely different problem (mailflow), I stumbled on my old response. I decided to tackle this today and I've found a solution that works for me. When I send a mail every time a node is saved (nodes contain headers as CCK fields), I do two steps:

1) Add an Arbitrary PHP Rule, weighted before the mail is sent, to set a session variable with the header in the rule.

$_SESSION['my_mail_headers']['in-reply-to'] = $node->field_in_reply_to[0]['value'];
$_SESSION['my_mail_headers']['references'] = $node->field_references[0]['value'];

2) Add a custom module with a hook_mail_alter function that adds elements to the $message['headers'] array.

function mymodule_mail_alter(&$message) {
  if (isset($_SESSION['my_mail_headers'])) {
    foreach ($_SESSION['my_mail_headers'] as $key => $value) {
      $message['headers'][$key] = $value;
    }
    unset($_SESSION['my_mail_headers']);
  }
}

I'd prefer not to use a session variable for this, but digging into the code for altering the rules form, having it store and recall data, and having that data parsed by token and eventually passed to drupal_mail made my brain explode this afternoon.

sadashiv’s picture

Component: Rules Engine » Rules Core
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new2.78 KB

Hi,

I was facing the same issue and thought of using hook_mail_alter and setting the headers for the message. It works but need to do it for all rules so modified the rules module to have this option to set header. I am attaching a patch which adds a header field in the "send mail" and "Send mail to all users of a role" where you can set headers for the mail. eg Content-Type: text/html; UTF-8\nMIME-Version: 1.0

Note that setting such headers can change the formatting, etc in the mail.

Please flush drupal cache after applying the patch else won't see the header field under rules UI

Hth,
Sadashiv

Status: Needs review » Needs work

The last submitted patch, 4: rules-779504-Add_arbitrary_mail_headers_to_mail_actions.patch, failed testing.

sadashiv’s picture

Status: Needs work » Needs review
StatusFileSize
new3.68 KB

I tried to fix one issue with the patch.

Thanks,
Sadashiv.

sadashiv’s picture

Priority: Normal » Major

Hi,

Would be great if someone can test, verify that patch works and move it ahead.

Thanks,
Sadashiv.

chris matthews’s picture

Priority: Major » Normal
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 3 year old patch in #6 does not apply to the latest 7.x-2.x-dev and if still relevant needs a reroll.

Checking patch modules/system.eval.inc...
Hunk #1 succeeded at 76 (offset 1 line).
Hunk #2 succeeded at 100 (offset 1 line).
error: while searching for:
 * Set's the message subject and body as configured.
 */
function rules_mail($key, &$message, $params) {

  $message['subject'] .= str_replace(array("\r", "\n"), '', $params['subject']);
  $message['body'][] = $params['message'];
}

error: patch failed: modules/system.eval.inc:145
error: modules/system.eval.inc: patch does not apply
Checking patch modules/system.rules.inc...
Hunk #1 succeeded at 212 (offset 4 lines).
Hunk #2 succeeded at 248 (offset 4 lines).
tr’s picture

Please, if you're going to do this, just trigger a retest of the most recent patch, then re-roll it yourself if it doesn't apply. That's what *I* did for all the NR issues in this queue over the past 6 months or so. You can see I triggered a re-test on 18 Aug 2018 and it still applied back then. I re-rolled all the patches that failed my retests, but I've done so much work on the code base that it's no surprise that these patches need re-rolls. In the case of this issue, it's a matter of only ONE APOSTROPHE that's preventing the patch from applying.

It's no help to mark everything as "Needs work". It's helpful to do the work that's needed...

sadashiv’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB

Hi,

Have rerolled the patch.

Hth,
Sadashiv.

tr’s picture

Version: 7.x-2.x-dev » 8.x-3.x-dev
Status: Needs review » Needs work
Issue tags: -Needs reroll +Needs tests

Evidently, there's not much interest in this feature - the last substantive contribution to this issue was more than 6 years ago.

D7 Rules is basically in maintenance-only mode right now, as D7 is nearing its end-of-life. So I'm moving this to the 8.x-3.x branch for consideration.

This patch needs to be re-rolled for D8 and reviewed, and we need some test cases to demonstrate this new feature works properly.

tr’s picture

Component: Rules Core » Actions