Hi every body,

I have been trying to make drupal send mail via an external smtp mail server, after reading a lot of posts on this forum I found one talking about smtp.module, so I installed it, I created a new account and the registration mail was delivered successfully to the e-mail address. So smtp.module works.

Then I installed simplenews module and I created a newsletter and added 2 testing susbcriptors, then send the news letter and in the next page I get the message: "Se ha creado su newsletter." (I am spanish so I am using the spanish translation :P ) that means something like "Your newsletter has been succesfully created" but when I look into the log at the administer menu I see 2 errors:

error simplenews 2006-03-14 12:51 Newsletter porca miseria could not be sent to +++@****.---
error simplenews 2006-03-14 12:51 Newsletter porca miseria could not be sent to 000@****.---

I do not post the original e-mail addresses in order to avoid spam. But the original addresses are right.

Any Idea of what could be happening?

Thanks :)
Martin.

P.D.: I use Apache 2.0.55, PHP 4.4.2 and Drupal 4.6.5

Comments

cosmoperis’s picture

I solved the problem.

I post here the solution I found and I hope this could help someone else.

I saw the post at http://drupal.org/node/29888 and I decided to try. I dissabled the smtp.module and installed class.smtp.inc and smt.inc as indicated on that post. I tried to add a new user account and the registration e-mail was delivered succesfully. But the module simplenews still didn't work so I decided to gon into the source code.

At file simplenews.module I found the code that sends the newsletters

<?php
/**
* Mail engine
*/
function sn_mail_send($mail) {
  $mail->to = trim($mail->to);
  require_once('activeMailLib.php');
  $email = new activeMailLib($mail->s_format);
  $email->From($mail->from_address, $mail->from_name);
  $email->To($mail->to);
  $email->Subject($mail->title);
  $email->Message($mail->message, 'UTF-8', $mail->encode);
  $email->priority($mail->priority);
  if ($mail->receipt) {
    $email->Receipt($mail->from_address);
  }
  $email->Send();
  return $email->isSent($mail->to);
}
?>

As you can see the $email->Send(); sends the e-mail, and it is defined in the file activeMailLib.php so I investigated a bit on that file and found out that it uses the php function mail() to send mail, and it dissabled on most systems, so I changed the mail() call for the one defined in Drupal user_mail()

Here is the code that I changed in activeMailLib.php:

<?php
function Send(){
$this->mkHeaders();
	if ($this->mailto && $this->mailfrom){
		foreach($this->mailto as $res){
		$serv=$this->mkCheckServer($res);
		$this->serv[$res]=$serv[1];//vamos a probar un hack a ver si hacemos que esto envie correo...
								//cambio la llamada a mail por la de user_mail_wrapper
			//-----------------------------CODIGO ORIGINAL-------------------------------------------------------------
			//if ($serv[0]==true) $this->mailsent[$res]=mail($res, $this->mailsubj, $this->mailbody, $this->mailheaders);
			//else $this->mailsent[$res]=false;
			//---------------------------------------------------------------------------------------------------------
			
//----------------------------HACK--------------------------------------
			
			if ($serv[0]==true) $this->mailsent[$res]=user_mail($res, $this->mailsubj, $this->mailbody, $this->mailheaders);
			else $this->mailsent[$res]=false;
			
                        $message=t('El resultado de user_mail: %resul',array('%resul'=>$this->mailsent[$res]));
			watchdog('activeMailLib', $message, WATCHDOG_WARNING);
		}
	}else{
		$message=t('Hay problemas con mailto y mailfrom ve a administer->settings y establece un nombre y un mail para el sitio');
		watchdog('activeMailLib', $message, WATCHDOG_WARNING);
//-------------------------Fin del HACK--------------------------------
	}
}
?>

One last thing... the from_address and from_name of the e-mail is extracted from the information defined in the section administer->settings from drupal, be sure that the fields Name and e-mail for the site are filled, if not the e-mail won't be delivered.

If anyone has troubles with something similar I would gladly help him. You can contact me at: marpemar(at)iti(dot)upv(dot)es

jdsaward’s picture

Thanks; I was having the same problem and your hack solved it for me.

John

ps Can you translate for me: "Hay problemas con mailto y mailfrom ve a administer->settings y establece un nombre y un mail para el sitio"

damianrr’s picture

There are troubles with the mailito and mailfrom fields go to administer->settings and set a name and a email for the site.

damianrr’s picture

Hi i try everything you say here and i get this error: "mail connect error: EHLO command failed"

my configurations is:

in class.smtp.inc

$this->host = 'smtp.google.com';
$this->helo = 'smtp.google.com';
$this->auth = TRUE;
$this->user = (my gmail username);
$this->user = (my gmail password);

in smtp.inc

$params['host'] = ini_get('SMTP');
// The smtp server port
$params['port'] = 465;
// What to use when sending the helo command. Typically, your domain/hostname
$params['helo'] = $_SERVER['HTTP_HOST'];
// Whether to use basic authentication or not
$params['auth'] = true;
// Username for authentication
$params['user'] = (my gmail username);
// Password for authentication
$params['pass'] = (my gmail password);

in my .htaccess

php_value SMTP smtp.gmail.com
php_value smtp_port 465

Any ideas will be most welcome.

damianrr’s picture

Oh i forget to ask, what is exactly the ehlo param??

cosmoperis’s picture

Hi Damian,

I've been taking a look to what you say. It seems that it successfully
gets the socket connection to smtp.google.com (otherwise the error "mail
connect error: Failed to connect to server" but for some reason the EHLO
command fails.

Is "mail connect error: EHLO command failed" all the information that
the error message gives to you? I've been checking class.smtp.inc and
the sourcecode says:

function ehlo(){
                        if(is_resource($this->connection) AND
$this->send_data('EHLO '.$this->helo)AND substr(trim($error =
$this->get_data()), 0, 3) === '250' ){

                                return TRUE;

                        }else{
                                $this->errors[] = 'EHLO command failed,
output: ' . trim(substr(trim($error),3));
                                return FALSE;
                        }
                }

So the error message should be something like this: "mail connect error:
EHLO command failed, output: ************"

The version of class.smtp.inc I am using is 1.0.5
The content of the variable $error would be very informative.

By the way you could check some things:

- Check the value returned by ini_get('SMTP')
- Check the value returnd by $_SERVER['HTTP_HOST']
- I have no account at gmail but the smtp server is smtp.google.com or
smtp.gmail.com?
- Gmail smtp server uses TSL, I've never dealed with that.

Answering to you question: Oh i forget to ask, what is exactly the ehlo
param??

The command HELO usually is the first command sent to the smtp server,
followed by your hostname. The only difference with EHLO is that if the
command EHLO is accepted the response of the server provides
computer-readable information about the server's abilities.

I hope that this give you some clues :)

Regards.

cutesimaus’s picture

I tried changing activeMailLib.php as suggested in your reply.
But I get an error when sending test emails.
It is saying there is an unexpepcted variable.

Could it be that there are extra spaces?

cutesimaus’s picture

Its working now.
But I am getting the ff error message:

5.7.1 ... SMTP relay denied, authenticate via POP/IMAP first
5.0.0 Need RCPT (recipient)

I guess I have to configure the mail server yet since it is on another domain.

iancawthorne’s picture

Any idea how to translate this across to 5.x verson of simplenews? The code pretty looks different.

Hydrant Ltd
www.hydrant.co.uk

getagb’s picture

I'd be interested in seeing it for 6.x