Hi guys,

Following up with the support request #2207357: Interoperable with Mail System and HTML Mail? in the Reroute Email tracker, it would be great if any users of HTML Mail / Mail System could report back on testing with Reroute Email:

ie. If I installed HTML Mail and used Mail System to swap it out as the default mailer, would Reroute Email still intercept and reroute these emails?

I'm not very familiar with HTML Mail and Mail System, but from what I've seen in the code, they would still seem to be using Drupal Mail API, implementing hook_mail and not directly using PHP mail functions.
So I would assume they should be compatible with Reroute Email (which implements hook_mail_alter), but would greatly appreciate more feedback and details.

Could anybody please provide more information or testing/reporting of using the Reroute Email module with HTML Mail and Mail System?

Feel free to let me know if you would have any questions, comments or concerns on this ticket, I would certainly be glad to provide more information or explain in further details.
Thanks to all in advance for your great help testing, reviewing, reporting, questions, comments and feedbacks.
Cheers!

Comments

David Hernández’s picture

Status: Active » Needs review

First of all, we need to understand how Drupal sends e-mails:

Drupal can handle multiple systems to send mails. There is a system variable (variable_get('mail_system') with the enabled systems to send e-mails. By default, there is only one, called DefaultMailSystem ( https://api.drupal.org/api/drupal/modules%21system%21system.mail.inc/cla... ). Those "systems" are classes that implement a default interface called MailSystemInterface ( https://api.drupal.org/api/drupal/includes%21mail.inc/interface/MailSyst... ).

This interface only requires two functions: format and mail. The first one handles the formating and the second one, sends it.

So, what causes your problem?

If you implement a mail system, you have to implement both methods, the format and the mail function. The HTML Mail module actually "only needs" to do the formating, meanwhile Reroute Email "only needs" the sending part. HTML Mail doesn't know that you have another system to send e-mails and Reroute Email doesn't know that you have another system to format the e-mails.

Is there a solution for this?

Yes, there is. You can implement your own MailSystemInterface in a custom class that does the formating of HTML Mail and the sending of Reroute Email. If you don't want to do this, the Mail System module has a functionality that does it for you.

Just go to admin/config/system/mailsystem and under "New Class" select for the format method the HTML Mail and for the mail method the Reroute Email and save the settings. This will generate a new class, called HTMLMailSystem__RerouteEmailSystem or something like that.

David Hernández’s picture

Assigned: Unassigned » David Hernández
Status: Needs review » Active

Ok, nevermind, just reviewed how Reroute Email works and doesn't implement it's own class. Sorry, I should have read better the issue description.

In the hook_mail_alter of the reroute_email module, there is only one place where the $message['to'] is altered, to reroute the e-mail:

    if (!in_array($to, $addresslist)) {
      // Not on the list, so reroute to the first address in the list.
      $message['headers']['X-Rerouted-Original-To'] = $to;
      $message['to'] = !empty($addresslist[0]) ? $addresslist[0] : REROUTE_EMAIL_ADDRESS_EMPTY_PLACEHOLDER;

So, unless the if condition is not being applied, I don't see why the reroute_email will not work with HTMLMail.

I'm trying this, to see what's going on.

David Hernández’s picture

Status: Active » Needs review

I should have started here:

Installed HTML Mail and Reroute Email. Enabled both modules, tried the send test email from html mail at admin/config/system/htmlmail/test

MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8Bit
X-Mailer: Drupal
Return-Path: info@example.com
Sender: info@example.com
From: "Info" <info@example.com>
X-Rerouted-Mail-Key: htmlmail_test
X-Rerouted-Website: http://drupal.local
X-Rerouted-Original-To: original@example.com
To: rerouted@example.com
Subject: test

<h1><a href="http://drupal.org/project/htmlmail">HTML Mail</a> test message</h1>
<div class="htmlmail-body">
This email was rerouted.
Web site: http://drupal.local
Mail key: htmlmail_test
Originally to: original@example.com
-----------------------
<br />
<br />
<p>test</p>
</div>

Can someone else verify that it works correctly?

David Hernández’s picture

Assigned: David Hernández » Unassigned
salvis’s picture

Status: Needs review » Closed (outdated)

No patch and not sufficient interest, sorry...