I see drupal_mail has some nice changes for 6.x so I think it really might be time for this suggestion.
Under Unix there is currently no way (that I know of) to set the envelope sender (Return-Path) using drupal_mail. From, Reply-To, Sender, etc are all set but for Return-Path (under Unix) requires the additiona sendmail paramer '-f sender@domain.com' to be passed into mail().
For some things this is important. For example, Verizon Wireless TXT messaging uses the Return-Path as the sender for text messages. Optionally adding this final mail() parameter would give complete control via drupal_mail.
Comments
Comment #1
panchoI'm seeing lots of problems with undelivered emails in the forums. Some of them are obviously connected to the missing return path issue, some not.
However, if we can easily solve at least a part of these problems, we should do it.
This would effectively mean we'd be adding the Return-Path module to core. This is a good thing because Return-path is by design not compatible with custom mail backends such as SMTP (see here), and we could solve that.
Comment #2
panchoI digged a bit into this.
There are at least three ways to add a Return-Path:
The problem with alternative (4) is that sendmail is usually configured to ignore 'Return-Path' in headers. My mail.rc says for example:
This means: the way drupal_mail() atm adds the 'Return-Path' header mostly results in the header being ignored.
In most cases, sendmail can fall back on either (3) or (2), or on (1). (This also means that mostly the 'Return-Path' set is not the one we want it to be but username@hostname or username@IP. This is not a big problem, and may even turn out to be better.)
Now, if (4) is ignored and (1) through (3) are not set, there will be no 'Return-Path' added at all. (That's not good for the SpamScore.)
What can we do?
Adding an additional parameter -f when calling PHP's mail function (3) works well. However if the -f parameter has already been set in PHP.ini (2), this results in sendmail being called with two '-f' parameters, which causes problems.
So we first figure out, if '-f' has already been set in PHP.ini and otherwise give it to mail().
Problems left
There are valid use cases to provide a 'site_mail' variable that is not located in the website's domain. In this case, mails tend to be flagged as Spam or not to be sent at all. As this is out of the scope of this issue here though, I created another issue for this: #346545: Add a 'site_mail_internal' address variable.
Comment #3
panchoHere's a patch that should fix this issue.
Comment #4
panchoNew version.
We better move the Return-Path from the headers to the extra parameter only after all hooks are invoked, so the hook implementations don't need to take care of that and no changes are needed there.
Comment #5
dries commentedYour patch assumes that sendmail is used. What happens when that is not the case?
Comment #6
gpk commentedAlso:
1. you can't use -f if safe mode is on
2. the example here http://uk2.php.net/manual/en/function.mail.php doesn't have a space between the -f and the address. See also http://www.sendmail.org/~ca/email/man/sendmail.html, which notes in addition that "-f can only be used by ``trusted'' users (normally root, daemon, and network) or if the person you are trying to become is the same as the person you are"
Comment #7
scor commentedsee #131737: Ensure that the Return-Path is set when sending mail on both Windows and non-Windows systems.
Comment #8
gpk commentedGuess I should continue in the other thread, but just to note that on Windows, you can ini_set sendmail_from and this sets the Return-Path header also. See http://uk.php.net/manual/en/mail.configuration.php.
Comment #9
pancho@dries:
For mailservers that work differently we have drupal_mail_wrapper(), but in fact we better move this code block further south so nothing is changed for implementations of drupal_mail_wrapper().
@gpk:
Also, I'm now checking safe_mode.
@scor:
Yes, indeed it's a duplicate, and of course I'm moving there. But you should have mentioned over there that there is a working patch for D7 in this thread, it could have get lost otherwise.
New patch, also posted to the original issue #131737: Ensure that the Return-Path is set when sending mail on both Windows and non-Windows systems..