The Return-Path is not set. The result of this, is that when using the "Full user data (User name and available user information)" option, all bounce messages (out of office, full mailbox etc.) go to the Drupal User who generated the notification.

Funny enough, elsewhere (in the messaging_mail_headers function) the correct headers are created, like:

    $more_headers['Sender'] = $more_headers['Return-Path'] = $more_headers['Errors-To'] = $default_from;

Adding the following lines of code to the messaging_phpmailer_drupal_mail function, solves this.

  if(!empty($message['headers']['Sender'])) {
    $mail->Sender = $message['headers']['Sender'];
  }
  if(!empty($message['headers']['Errors-To'])) {
    $mail->AddCustomHeader($message['headers']['Errors-To']);
  }

(PHPMailer creates the Return-path header from the Sender.)

Comments

danepowell’s picture

I can't speak to the efficacy of this patch. It occurs to me though that we may not want replies to go to the site address, since there's a good chance that it's simply a "dummy" unmonitored account...

batje’s picture

On mailinglists, the return-path is mostly used exactly for this. It will prevent all errors & out-of office messages to go to the person who just posted a blog, or a forum-post or anything else that people have subscribed to. The Reply-To field is used by email clients to send the real reply to.

In our scenario, we use mail2web & og & og_forum to mimic mailinglists. Drupal sets the FROM address to the users email, mail2web sets the Reply-To address to replies@example.com, and this code only fills in the Return-Path & Error-To to the site-email. All bounces end up in the site-email, all replies go to replies@example.com.

(I did not test without mail2web, but from reading the code, i think the FROM will still be the Drupal Users Email address)

A solution for the 'no read of replies' would be to make Return-Path & Errors-To configurable.

(and once we have that, we could think about proper bounce-handling, where all 'Mailbox does not exist' users would be disabled, etc. As the whole mailer-issue seems to be overhauled in Drupal 7, we might want to wait with this, though.)

batje’s picture

Ah, and on a second note, this patch (the second part of code) does not set the Return-Path. It only sets the Return-Path to the value that is provided.

this code (that sets it):

$more_headers['Sender'] = $more_headers['Return-Path'] = $more_headers['Errors-To'] = $default_from;

is already in the module. Changing this, is another patch.

danepowell’s picture

I agree that this should be implemented. I would like to let admins select the Return-Path and Errors-To addresses that they want to use for Messaging. I will take a look at ways of implementing this. As you point out, this might require some deeper changes than just to PHPMailer.

danepowell’s picture

Status: Active » Needs review
StatusFileSize
new3.53 KB

Okay, try out this patch against 6.x-2.1. Note that if you've installed some other similar recent patches (allowing for BCC sending and custom from headers) that share features with this patch, you may have to apply it manually.

danepowell’s picture

StatusFileSize
new3.52 KB

Whoops, there was a problem with that patch that I didn't notice due to my restricted testing environment. This one should work.

danepowell’s picture

Version: 6.x-2.1 » 6.x-2.2
StatusFileSize
new3.52 KB

Very minor change to fix formatting (thanks, Coder module :) )

danepowell’s picture

Can someone please verify patch in #7 so we can get this committed to 2.x and focus on porting it to 4.x?

danepowell’s picture

Version: 6.x-2.2 » 6.x-4.x-dev
Status: Needs review » Patch (to be ported)

This has been fixed in 2.x but needs to be ported to 4.x

jose reyero’s picture

Status: Patch (to be ported) » Closed (fixed)

Merging with #260595: More flexible message headers and working on a simpler solution for 4.x