Page 1 of 1

Error sending email

Posted: Thu Oct 11, 2012 12:28 pm
by massiws
Hi, I set a button in Extra Action Buttons with this code:

Code: Select all

var pCode     = "rptXYZ";
var pTo       = "";
var pFrom     = "admin@domain.com";
var pSubject  = "New invoice";
var pMessage  = "Attached is ....";
var pFilename = "invoice.pdf";
var pResponse = "";
var pType     = "PDF";
emailIt(pCode,pTo,pFrom,pSubject,pMessage,pFilename,pResponse,pType);
I'm sure email settings in Setup are correct, but nuBuilder can't send email: it answare "There was an error sending the email".
I've tryed also setting up a gmail account, with the same result.
I've tryed to pass PDF or HTML in pType parameter, change yes/no SSL in Setup>Email settings, setting up a gmail account, getting the same result.

Reading the wiki http://wiki.nubuilder.com/tiki-index.ph ... nse_pType_ something is not clear or can be confusing:
in wiki you wrote:emailIt(pCode,pTo,pFrom,pSubject,pMessage,pFilename,pResponse,pType)
This will email a Report with the same activity code as pCode.
pReportID cannot be left blank, this is code of the report you wish to email.
pCode parameter in emailIt() function is the activity code (ex: rptXYZ) or recordID in zzsys_activity table (ex: 14ffbf0ca...)? What is pRecordID referred to? :?:
However, also replacing activity-code with record-id the result is the same. :(

Did I forget something?

Re: Error sending email

Posted: Thu Oct 18, 2012 12:47 am
by pickle_jimmy
Hi Massiws,

Sorry for the time it has taken me to reply.

First: email can be a pain; that said - When I was troubleshooting our email, I wrote this little php file, and ran it from the command line of our server (eg. save the below code to email.php, then run "php email.php" at the command prompt)

Code: Select all

<?php
$emailAddress = "myusername@gmail.com";
$emailPassword = "mypassword";
$smtpServer = "smtp.gmail.com";
$smtpSSLPort = "465";

// make sure path to phpmailer is correct for you
require_once("phpmailer-5.1/class.phpmailer.php");

$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = $smtpServer; // SMTP servers
$mail->Port = $smtpSSLPort;  // SMTP Port
$mail->Username = $emailAddress; // SMTP username
$mail->Password = $emailPassword; // SMTP password

$mail->From = $emailAddress;
$mail->FromName = "nuBuilder";
$mail->AddAddress("otheremail@hotmail.com","OtherName");
$mail->AddReplyTo("otheremail@hotmail.com","OtherName");

$mail->WordWrap = 80; // set word wrap

$mail->IsHTML(true); // send as HTML

$mail->Subject = "Test Hello World Email";
$mail->Body = "This is the <H1>HTML</H1> body.<BR><BR><H2>Hello World</H2>";
$mail->AltBody = "This is the text-only body. Hello World";

if(!$mail->Send())
{
echo "Message was not sent";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>


Change the username/password/host to match your settings.

This will give a better idea of what is happening - the error wont be obscured by nuBuilder.

Let me know how you get on.

Cheers

Pickle Jimmy

Re: Error sending email

Posted: Thu Oct 18, 2012 7:06 pm
by massiws
Pickle Jimmy,

thanks for reply.
I try your code, as well as the code examples in phpmailer folder: emails are correctly sent with these settings (by my provider):

Code: Select all

    $emailAddress  = "admin@myDomain.it";
    $emailPassword = "myPassword";
    $smtpServer    = "mail.myDomain.it";
    $smtpSSLPort   = "26";

    // make sure path to phpmailer is correct for you
    require_once("production2749/phpmailer/class.phpmailer.php");

    $mail = new PHPMailer();
    $mail->IsSMTP(); 				// send via SMTP
    $mail->SMTPAuth   	= true; 		// turn on SMTP authentication
    // $mail->SMTPSecure 	= 'ssl'; 	// secure transfer enabled REQUIRED for GMail
    $mail->Host       	= $smtpServer; 		// SMTP servers
    $mail->Port       	= $smtpSSLPort;  	// SMTP Port

    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
I cant' be able to make it work with gmail settings (also uncomment $mail->SMTPSecure = 'ssl';).
Putting the same parameters in Setup > EmailSettings the emailIt() function don't work: can I test something else?

Can you better clarify the quoted wiki about pCode and pReportID parameters in emailIt() function?

Thanks

Re: Error sending email

Posted: Mon Oct 22, 2012 1:54 am
by pickle_jimmy
Hi Massiws,

First up - I wrote a little procedure in nuBuilder (it might be added to the new base system) which tests your email settings

Code: Select all

require_once("emaillib.php");

$sql="SELECT * FROM zzsys_setup";
$res = nuRunQuery($sql);
if($row = db_fetch_array($res)) {
  $SMTPhost = $row['set_smtp_host'];
  $SMTPport = $row['set_smtp_port'];
  $SMTPauth = $row['set_smtp_use_ssl'];
  $SMTPuser = $row['set_smtp_username'];
  $SMTPpass = $row['set_smtp_password'];
  $SMTPfrom = $row['set_smtp_from_address'];
  $SMTPfnam = $row['set_smtp_from_name'];
  $content = "<H1>Test Email Settings</h1>";
  $subject = "Test Email Settings";

  $mail              = new PHPMailer();
  $mail->IsSMTP();
  $mail->Host     	  = $SMTPhost;
  $mail->Port     	  = $SMTPport;
  $mail->SMTPSecure 	= $SMTPauth ? 'ssl' : '';
  $mail->SMTPAuth 	  = $SMTPauth;
  if ($SMTPauth) {
    $mail->Username  = $SMTPuser;
    $mail->Password  = $SMTPpass;
  }
	
		$mail->From        = $SMTPfrom;
  $mail->AddAddress($SMTPfrom,$SMTPfnam);
  $mail->AddReplyTo($SMTPfrom,$SMTPfnam);
  
		$mail->AddReplyTo  = $SMTPfrom;
		$mail->AddAddress  = $SMTPfrom;
		$mail->WordWrap    = 80;
		$mail->IsHTML(true);
		$mail->Subject     = $subject;
		$mail->Body        = $content;

  if(!$mail->Send()) {
    echo "Error sending: " . $mail->ErrorInfo;;
  } else {
    echo "Test sent";
  }  
  
}
But, in answer to your initial question, these are MY personal settings which I put into nuBuilder:

Authenticated SMTP settings - username@Email.Address
Auth SMTP username - username
Auth SMTP password - password
Auth SMTP host - smtp.domain.com
Auth SMTP From Address - username@Email.Address
Auth SMTP From Name - SomeName
Auth SMTP port - 26
Auth SMTP use SSL - No

I have a NON SSL auth email provider that also uses port 26. I set SSL to NO, and everything works.

Give it a go.

Cheers

Pickle