Some mailers (I've had this issue with qmail in the past) request SMTP Return-Path parameter to be explicitely passed through -f parameter, otherwise they refuse to handle messages. That's when I've had to do a quick and dirty solution for my problem.

Now, I am using postfix (and, miss qmail sometimes a lot...), which doesn't complicate that much, but throws into the message header a Return-Path paramater "" instead of "", which would probably be much more normal to the recipients, and enable possible error messages to reach the webmaster...

To resolve the issues above, I've introduced another variable "smtp_return_path" admin can use; it can be empty (in this case, NULL is passed to mail() as an optional parameter), or any arbitrary e-mail address can be specified (I use webmasters address - in this case, "-f webmaster@my-web-server" string is passed as an optional parameter to the mail() function call).

My patch is in attachment. In case of an empty "SMTP Return-Path address" field, nothing shall be changed in functionality. I would be very happy if this can be adapted and I wouldn't have to patch all of the future versions to get the desired functionality... ;-)

Comments

allie micka’s picture

Status: Active » Closed (won't fix)

On the PHP documentation page for mail():

The additional_parameters parameter is disabled in safe_mode and the mail() function will expose a warning message and return FALSE when used.

This means that applying your patch will render mimemail inoperable for anyone running safe_mode. That would be bad :).

By setting Return-Path and Errors-To headers, mimemail can convince most MTA's to set the correct envelope sender for your messages. In cases where this won't work, you would be better off using the SMTP Authentication module as a mimemail backend, which covers more bases.

Thanks!

gnosis’s picture

StatusFileSize
new1.83 KB

For anyone who does decide to use this patch, there is a little bug in it that caused me a bunch o' gray hair (http://drupal.org/node/297048). There should not be a space after the -f option. Here's an updated patch without the space.

luti’s picture

I agree with #1 statement, but isn't it possible to find a solution where it would be possible to set SMTP Return-Path parameter in an acceptable way? I mean, I urgently need it, as I was not able to convince my qmail to accept the message without.

Or, can you explain a bit better this, Allie, please:

In cases where this won't work, you would be better off using the SMTP Authentication module as a mimemail backend, which covers more bases.

Maybe I can resolve my problem this way, but I need to know what to change and where to achieve that.

About #2: my patch works for me without a problem, but as message is accepted also with this option without a space, your patch is better, I agree.

mfb’s picture

Status: Closed (won't fix) » Needs review
StatusFileSize
new2.53 KB

For my application I need to be able to set various envelope sender addresses for various types of outgoing messages, for correct bounce handling among other reasons. The attached patch adds an advanced option for setting the envelope sender address, and it will not cause the problem Allie noted at #1, as it checks the safe_mode ini setting before calling mail() with the $additional_parameters.

yan’s picture

mfb: Isn't that a different issue?

Has the return path problem of this module still not been solved? I'm having the same issue: When the mime mail module is enabled and used, the Return Path module doesn't have any effect and the return path is set wrong.

mfb’s picture

@yan: I'm glad you brought this up, as I was recently looking at the Return Path module and noticing that it doesn't work with Mimemail. Perhaps another way to resolve this issue would be to patch the Return Path module to function as a backend for Mimemail? I haven't yet had a chance to look into this.

mrfelton’s picture

StatusFileSize
new1.88 KB

I too found the returnpath module, and realised it doesn't work with mimemail. I need this functionality. My version of the patch also allows for the sender name to be in the format "Site Name" <user@example.com>, which I enable in a custom module like so:

/**
* Implementation of hook_mail_alter().
* Here we allow the site name to be used as the senders name for outgoing email.
* see http://drupal.org/node/209672
*/
function mymodule_fast_mail_alter(&$message){
  $default_from = variable_get('site_mail', ini_get('sendmail_from'));

  if($message['from'] == $default_from){
    $message['from'] = '"'. variable_get('site_name', 'Drupal') .'" <'. $default_from .'>';
    $message['headers']['From'] = $message['headers']['Sender'] = $message['headers']['Return-Path'] = $message['headers']['Errors-To'] = $message['headers']['Reply-To'] = $message['from'];
  }
}
Robert Molenaar’s picture

Hello mrfelton ,

Your solution works fine! I did something similar, (see http://drupal.org/node/338123 #5), but your solutions is nicer..

Thank you.

sgabe’s picture

StatusFileSize
new3.23 KB

Patch doesn't work with safe_mode.

SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE MODE.

We have to check the safe_mode first and we shall pass the additional parameter to the mail() function according to the result.

I am attaching a revised patch of #7.

sgabe’s picture

StatusFileSize
new3.22 KB

Sorry, in my patch the if statement is wrong. I attached the good one, please use this.

drupalfan2’s picture

Status: Needs review » Patch (to be ported)

Patch #10 does NOT work with mimemail + simplenews: Every time a message is sent with simplenews, error log shows that the message has not(!) been sent successfully.

Patch #4 works fine.

When will a fine working version of this patches be applied to mimemail?

sgabe’s picture

Status: Patch (to be ported) » Needs review

@DrupalFan2: Please, read the documentation about issue status settings.

sgabe’s picture

StatusFileSize
new2.06 KB

I am attaching a new patch against current HEAD with Return-Path handling retrieved from Drupal 7.

Riggs333’s picture

Thanks sgabe!

The patch mimemail.261028_04.patch (#13) seems to work for me with drupal 6.19.

marcvangend’s picture

sgabe: regarding the patch in #13, why do you check if the return path has already been set in the server configuration ($return_path_set = strpos(ini_get('sendmail_path'), ' -f');)?

I just had to apply your patch in a shared hosting environment where the sendmail_path by default contained a return path (set in the VirtualHost directive in httpd.conf) that I didn't want to use, causing the patch to do nothing. I changed the patch so the return-path is always set by the script, regardless of the php configuration:

+      // If 'Return-Path' isn't already set in php.ini, we pass it separately
+      // as an additional parameter instead of in the header.
+      // However, if PHP's 'safe_mode' is on, this is not allowed.
+      if (isset($message['headers']['Return-Path']) && !ini_get('safe_mode')) {
+        $message['Return-Path'] = $message['headers']['Return-Path'];
+        unset($message['headers']['Return-Path']);
+      }

Do you have a use case where the -f option of the send_path value of the php configuration must have preference over the return-path value set by the Drupal module?

sgabe’s picture

@marcvangend: The patch is retrieved from D7, it's original issue is #131737: Ensure that the Return-Path is set when sending mail on both Windows and non-Windows systems.. I guess if the -f parameter has already been set in php.ini and we don't check that, it results in sendmail being called with two '-f' parameters, which is not so good. However I think you should share your opinion and ask your questions in the original issue.

lubnax’s picture

subscribing

burlap’s picture

It doesn't work for me. It seems that sendmail -f doesn't accept <mail@example.com> (resulting in no mail being sent at all) format, but it'll work with mail@example.com.

My quick and dirty hack (line 145 of mimemail.module):

$message['Return-Path'] = trim($message['headers']['Return-Path'], '<,>');

Also, it seems that I don't need this patch at all, I get the Return-path without the -f option anyway.

eaajithe’s picture

Version: 7.x-1.x-dev » 6.x-1.0-alpha8
StatusFileSize
new672 bytes

Following works for me. I needed to get bounces to the email I set as "From"
I applied the attached patch to mimemail-6.x-1.0-alpha8 version.
It works great.

sgabe’s picture

Works for you but will throw an error for anybody who uses safe mode. You should reroll and test the patch in #13.

luti’s picture

StatusFileSize
new3.05 KB

To avoid patching mimemail (for the reson above, as well as to make my life easier - simply updating mimemail from time to time, without a need to recheck everything, and patch new version again and again...), I've created some time ago a separate module to fix this issue. Here it is, if anyone wants to give it a try.

Any feedback is of course more than welcome. ;-)

earth1’s picture

After I sent a newsletter this came up. SMTP Error: Could not connect to SMTP host.. I did not get an email.

What shall I do?

Any help would be much appreciated.

luti’s picture

@earth1,

as first, it would be good to describe more in detail what your environment is (Win$, linux, which mail server you have, can you send mails through it otherwise etc.), and how the mail system is supposed to work (what are your php.ini settings).

I guess you have a more general problem at the moment, not what this issue is about...

agence web coheractio’s picture

subscribing

sgabe’s picture

Version: 6.x-1.0-alpha8 » 6.x-1.x-dev
StatusFileSize
new2.34 KB

I am attaching a new revised patch against the current development snapshot.

sgabe’s picture

StatusFileSize
new2.36 KB

New patch on the basis of #18.

sgabe’s picture

Status: Needs review » Fixed

Committed to the development snapshot.

earth1’s picture

@LUTi

My environment is linux. Mime Mail sent the email through email engine drupal_mail() and the email was OK. SMTP is the issue. I don't know where the php.ini settings? Do you have any suggestion or do you have more questions?

sgabe’s picture

SMTP is the issue

Then you should try in the SMTP issue queue.

luti’s picture

@earth1,

php.ini is most probably in /etc (as mainly all other settings in linux). Do you manage this linux server by yourself? ;-)

And, how can the email be OK, when SMTP doesn't work? I'm not sure I understand exactly your issue...

Try to see the log files (usually in /var/logs), if you can be more precise about what exactly the problem is (logged errors and warnings). When you know exactly what you have to fix, it is usually very simple to resolve it nowadays (google & co.).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

frederickjh’s picture

Issue summary: View changes

I know that this issues is closed.
I just wanted to say thanks to @LUTi for sharing the custom module. Save the day for me. I moved to new hosting where I could not use a setting in a custom php.ini.

Your custom module works great!

Thanks and God Bless!
Frederick