I often receive Drupal.org e-mails from the group I have suscribed to, or from other members through the e-mail contact form in my junk folder in hotmail. I never bothered too much with that as I check this folder also.

Then I started to experience more serious problems. My ISP host is not accepting any of the e-mails I sent from my Drupal install on Dreamhost. Mail is not delivered. I get an e-mail back in Dreamhost that says something along the lines that the e-mail failed to be delivered because the other host considered it abusive.

I inquired about this with my ISP provider. They suggest I use a fifth argument when using the php function mail().

I am gonna try that. I will seriously need to hack Drupal's code for this, and maybe someone can help me...? I just need to know which function to change... then I'll look up all instances where that function is called.

Researching into this matter, I found this, in a David Power's book I bought (a most remarkable php book by the way) : Php Solutions :

Most people are unlikely to need the fifth argument, although some hosting companies now make it a requirement. It ensures that the email is sent by a trusted user, and it normally consists of -f followed (without a
space) by your own email address, all enclosed in quotes. Check your hosting company’s
instructions to see whether this is required and the exact format it should take.

In understand Drupal's code enough to understand that this fifth argument isn't being used.

Once I test this, and if this helps me solve the problem with my ISP provider, I could describe the changes to be made, create a patch, then someone understanding CVS could change the header of this patch and he/she could submit it.

Thanks for your help on this.

Comments

Chill35’s picture

Here is the code which I think deals with sending e-mails from drupal in modules/user.module :

 function user_mail($mail, $subject, $message, $header) {
  if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
   include_once './' . variable_get('smtp_library', '');
    return user_mail_wrapper($mail, $subject, $message, $header);
  }
  else {
    /*
    ** Note: if you are having problems with sending mail, or mails look wrong
    ** when they are received you may have to modify the str_replace to suit
    ** your systems.
    **  - \r\n will work under dos and windows.
    **  - \n will work for linux, unix and BSDs.
    **  - \r will work for macs.
    **
    ** According to RFC 2646, it's quite rude to not wrap your e-mails:
    **
    ** "The Text/Plain media type is the lowest common denominator of
    ** Internet e-mail, with lines of no more than 997 characters (by
    ** convention usually no more than 80), and where the CRLF sequence
    ** represents a line break [MIME-IMT]."
    **
    ** CRLF === \r\n
    **
    ** http://www.rfc-editor.org/rfc/rfc2646.txt
    **
    */
    return mail(
      $mail,
      mime_header_encode($subject),
      str_replace("\r", '', $message),
      "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header
    );
  }
} 

Questions :

  1. Is this the code...?
  2. Where (in which file & line) is user_mail_wrapper() defined ?

Info on mail() found on http://ca3.php.net/manual/en/function.mail.php.

Caroline

Chill35’s picture

Example of use :

 $from    = "chill35@mySite.com";
$to      = "someone@hotmail.com";
$copy = "joe@mySite.com";
$headers = "From: $from\n";
$headers.= "Reply-To: $from\n";
$headers.= "X-Mailer: PHP/".phpversion()."\n";
$headers.= "Cc: $copy\n";
$sujet   = "Testing...";
$txtmsg  = "Hi there!";
$ok = mail($to, $sujet, $txtmsg, $headers, "-f $from");
if($ok) { drupal_set_message("Lovely!") }
else { echo "Roger, that's not working." }; 

Caroline

Chill35’s picture

The following thread : http://drupal.org/node/59085 talks about fixing delivery issues with a -f parameter in what I assume is the php.ini file, but I am not sure. It was actually TWO problems. It's fixed, now. One of the problems WAS that the mail was being bounced. The other was just a little tweak as far as WHO the mail was being sent from. "-f" (if that means anything to anyone).

I think I am definately on to something here.

Please help. I am far from being an expert with mailing.

pwolanin’s picture

Does adding the "-f $from" make it work?

As one option, rather than hacking the core code, it looks like you can just set the variable "smtp_library" to point to a customized include file, and then implement user_mail_wrapper().

Maybe for 5.x (or 6.x) this last parameter should be set?

---
Work: BioRAFT

Chill35’s picture

I haven't tried it yet because I can't find where the user_mail_wrapper() function is defined.

Do you know ?

As one option, rather than hacking the core code, it looks like you can just set the variable "smtp_library" to point to a customized include file, and then implement user_mail_wrapper().

Sounds like a great idea! What is smtp_library ?

Caroline

markhope’s picture

I've got similar concerns as I'm about to start mailing out using simplenews module.
AOL seem to cause the most problems, with a lot of new user confirmation emails never being delivered.

Might the smtp module help as it enables mail to be sent through an authenticated smtp server?
http://drupal.org/project/smtp

Mark

Chill35’s picture

The problem I am experiencing with my own ISP provider (with my university) is that Drupal e-mails get bounced back. So you may indeed very well experience the same problem as I do. In dreamhost (my hosting cie), I do receive an e-mail telling me that my e-mails have not been accepted by my ISP provider. (But they are accepted by hotmail & other mail services).

I understand that contributed modules usually resort to Drupal functions to send e-mails. Actually I remember seeing much contributed stuff which was directly using mail(), which isn't such a good idea.

The SMTP module might help.

I am very interested though in getting the core improved on this matter.

Let's keep on helping one another with this.

Caroline

Chill35’s picture

The question is : what is an authenticated SMTP server ?

Mine (I think) is authenticated allright insofar as that I can send and receive e-mails with it, except when it comes to Drupal and a few receiving ends, like my own ISP provider. And you the same : you experience problems with Drupal when AOL is the receiving end.

markhope’s picture

I have quite a large number of AOL users that have never logged into the site - meaning that the user confirmation email has probably never been received.

The question is : what is an authenticated SMTP server ?
Sorry that should be an SMTP server requiring authentication.

My thought is that some mails may get blocked because they are being generated by the mailing scripts - maybe something in the headers?
Like the Return-Path not being set correctly?

AOL (for instance) has guidelines for accepting mail: http://postmaster.aol.com/guidelines/standards.html
In the guidelines it states "AOL may reject connections from senders who are unable to accept at least 90% of the bounce-return messages (mailer-daemon failure/error messages) destined for their systems."

If the Return-Path isn't set correctly this will prevent bounce-return, so I thought that by sending mail through SMTP might give more acceptable headers. I too am no mail server expert so I'm just guessing.

The Return-Path module solves this problem, however I'm using simplenews/mimemail modules and this doesn't seem to set the path correctly. The standard Drupal emails are set correctly though.

Having just looked over returnpath module it might be your answer...
This module resolves the problem by parsing out the return-path set by Drupal modules, and passing it
to the sendmail binary using the -f option, rather than sending it only in the $headers parameter of the
mail() command.

Chill35’s picture

Having just looked over returnpath module it might be your answer...
This module resolves the problem by parsing out the return-path set by Drupal modules, and passing it
to the sendmail binary using the -f option, rather than sending it only in the $headers parameter of the
mail() command.

There you go! It's that -f option, that fifth argument. Headers are the fourth argument.

I will look into the contrib module. Then I will file a request or submit a bug about this with Drupal 5 or 6. I suspect that we will run into more and more problems in the future as mail services are trying to overcome spam.

Caroline

Chill35’s picture

Good find by the way!

http://drupal.org/project/returnpath

Description :

Most mail servers appear to over-write any 'Return-path' headers sent by the PHP mail() function.
The 'Return-Path' value is used by some mail servers to send bounce back emails. A lot of web hosting
companies send emails out with a return-path email based on the account name Apache runs as on the
server, e.g. apache@example.com or nobody@example.com

One solution is to define the -f sendmail parameters in the php.ini 'sendmail_path'.

This is no good when running a single Apache instance with PHP as there is only one php.ini and you
need to specify different return addresses for each domain.

This module resolves the problem by parsing out the return-path set by Drupal modules, and passing it
to the sendmail binary using the -f option, rather than sending it only in the $headers parameter of the
mail() command.

Chill35’s picture

The returnpath module does not fix my problem unfortunately.

Chill35’s picture

Here is what I am getting on my end (the e-mail is bounced) :

<****@****.ca>: host mail3.****[x.x.x.x] said: x x.x.x
<****@*****.ca>... REJECT 550 rejet:abus/abuse - xxxx -
x.x.x.x (in reply to RCPT TO command)

markhope’s picture

After a quick google for"REJECT 550 in reply to RCPT TO command"

If an MSA is not able to determine a return path to the submitting user, from a valid MAIL FROM, a valid source IP address, or based on authenticated identity, then the MSA SHOULD immediately reject the message. A message can be immediately rejected by returning a 550 code to the MAIL FROM command.

Is the 'from' email address you are using valid? Is it capable of receiving mail or is it a dummy donotreply@example.com type address?

Also can you do a reverse DNS lookup for the domain?
Try dnsstuff.com

Chill35’s picture

Is the 'from' email address you are using valid? Is it capable of receiving mail or is it a dummy donotreply@example.com type address?

When I get the same e-mail in hotmail.com for example, I can reply to it there. The from e-mail address is valid.

Also can you do a reverse DNS lookup for the domain?
Try dnsstuff.com

Ok, something else to learn :) Will look into this.

Thanks for having looked for a description of the error!

I so much wished that the e-mails wouldn't bounce... at least get into the junk filter. That ISP has filters for spam. It's my university ISP and it's important that people at my university can use my web site.

Shai’s picture

Here is what the host wrote to me when he discovered the problem:

In cpanel (he means the cpanel view for hosts -- not the cpanel icons we lowly clients see) under mail server -> configuration -> tweak settings, there is an option to turn on or off :

Prevent the user "nobody" from sending out mail to remote addresses (PHP and CGI scripts generally run as nobody if you are not using PHPSuexec and Suexec respectively.)

I switched this setting from "on" to "off" to solve the problem.

I hope this helps others, I'm so relieved.

Shai

bacchus101’s picture

Update for returnpath:

http://drupal.org/node/111831

This thread saved my life! I just moved to 1&1 and spent at least 10 hours troubleshooting this to try to get mail sent from my website roadrulesrevenge.com!

Thanks everyone! Return path worked!