Solved

SMTP authentication error using PHP

Posted on 2010-08-25
42
10,402 Views
Last Modified: 2013-12-13
I'm trying to use PHP to send a response when needed from my website with the appropriate company email address and keep getting errors.  Originally the emails were not authenticated but then certain users where not receiving them.  I've since tried added authentication and still no luck.  I put the code below and the errors.  

I've also tried port 465 which is the alternate smtp port provided by the hosted exchange service.  I've verified smtp relay is active.  I've also verified I'm getting a response by telneting to both ports of my smtp server.

CODE
<?php
require("class.phpmailer.php");
 
$mail = new PHPMailer();
 
$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->Host = "my.mail.server:25";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "my@email.com";  // SMTP username
$mail->Password = "mypassword"; // SMTP password
$mail->From = "my@email.com";
$mail->FromName = "Me";
$mail->AddAddress("my@email.com", "me");
 
 
$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML
 
$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";
 
if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}
?>

ERROR:
SMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
0
Comment
Question by:Dean_Kletter
  • 21
  • 13
  • 8
42 Comments
 

Author Comment

by:Dean_Kletter
ID: 33526505
here is an additional thought.  This is a private server but there are several other php websites being hosted on it much like a co-op server.  After digging around I'm wondering if I needed to edit any of the php.ini email.ini or smtp.ini files?  Some say localhost and my thinking was the variables I used the code would override but didn't know if that was incorrect or there was something I needed to address elsewhere?
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 33531276
Have you actually gone through authentication in your telnet attempts?  If you need the structure, see here: http://www.webpan.com/Customers/Email/SMTP_Authentication_Telnet_Test.htm

You have already verified with your host whatever your phpinfo() shows for the SMTP configuration item?
0
 

Author Comment

by:Dean_Kletter
ID: 33531472
I thought I had run through the verification, but this looks more comprehensive than what they exchange host provided.  Running through this now.  Yes, SMTP configuration was verified by provider.
0
 

Author Comment

by:Dean_Kletter
ID: 33531550
504 5.7.4 Unrecognized Authentication Type error after I typed AUTH LOGIN

that's the same error I'm getting in my code.
0
 

Author Comment

by:Dean_Kletter
ID: 33531585
I changed authentication type to 'false' and get this error....

SMTP -> FROM SERVER:530 5.7.1 Client was not authenticated
SMTP -> ERROR: MAIL not accepted from server: 530 5.7.1 Client was not authenticated
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33531944
Can you ...

$mail->SMTPDebug = true;
$mail->isSMTP(true);

// May or may not be needed ...
$mail->Mailer = 'smtp';



When you next try telnetting, can you read http://cr.yp.to/smtp/ehlo.html ...

"EHLO is just like HELO except that the server's response text provides computer-readable information about the server's abilities."

Ideally we want to see something like ...

250-AUTH LOGIN DIGEST-MD5 CRAM-MD5 PLAIN

in the response.

I suspect no LOGIN or no AUTH at all.

0
 

Author Comment

by:Dean_Kletter
ID: 33532010
Wow, got a lot more error details but the same result.  trying the second suggestion for telnet testing.

SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 my.mail.server.net Microsoft ESMTP MAIL Service ready at Thu, 26 Aug 2010 07:16:30 -0700 "
SMTP -> get_lines(): $data is "220 my.mail.server.net Microsoft ESMTP MAIL Service ready at Thu, 26 Aug 2010 07:16:30 -0700 "
SMTP -> FROM SERVER:220 my.mail.server.net Microsoft ESMTP MAIL Service ready at Thu, 26 Aug 2010 07:16:30 -0700
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-my.mail.server.net Hello [123.123.123.123] "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] "
SMTP -> get_lines(): $str is "250-SIZE 52428800 "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 "
SMTP -> get_lines(): $str is "250-PIPELINING "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING "
SMTP -> get_lines(): $str is "250-DSN "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $str is "250-STARTTLS "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS "
SMTP -> get_lines(): $str is "250-AUTH "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH "
SMTP -> get_lines(): $str is "250-8BITMIME "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME "
SMTP -> get_lines(): $str is "250-BINARYMIME "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $data was "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $str is "250 CHUNKING "
SMTP -> get_lines(): $data is "250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME 250 CHUNKING "
SMTP -> FROM SERVER: 250-my.mail.server.net Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME 250 CHUNKING
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "504 5.7.4 Unrecognized authentication type "
SMTP -> get_lines(): $data is "504 5.7.4 Unrecognized authentication type "
SMTP -> ERROR: AUTH not accepted from server: 504 5.7.4 Unrecognized authentication type
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 2.0.0 Resetting "
SMTP -> get_lines(): $data is "250 2.0.0 Resetting "
SMTP -> FROM SERVER:250 2.0.0 Resetting
SMTP Error: Could not authenticate.
0
 

Author Comment

by:Dean_Kletter
ID: 33532062
This is were I got.  I typed AUTH LOGIN after a signification delay after the last 250 line.

220 my.mail.server.com Microsoft ESMTP MAIL Service ready at Thu, 26 Au
g 2010 07:21:09 -0700
EHLO
250-my.mail.server.com Hello [123.123.123.123]
250-SIZE 52428800
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-AUTH
250-8BITMIME
250-BINARYMIME
250 CHUNKING
AUTH LOGIN
504 5.7.4 Unrecognized authentication type
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33532232
So, no AUTH LOGIN support. Just AUTH.

Not exactly sure (yet) how to proceed.

In the telnet session, when you get to the AUTH LOGIN stage, just type AUTH.

What response do you get?
0
 

Author Comment

by:Dean_Kletter
ID: 33532287
Same,

504 5.7.4 Unrecognized authentication type
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33532460
Looking at http://en.wikipedia.org/wiki/SMTP_Authentication#Details

"As with all SMTP extensions, SMTP AUTH is advertised in the EHLO response, along with a list of supported authentication methods. These methods may change after issuing STARTTLS, typically allowing plain text passwords in the latter case only. For example (from rfc4954):"

So

EHLO your.server.name.here
STARTTLS
EHLO your.server.name.here

What output now?
0
 

Author Comment

by:Dean_Kletter
ID: 33532555
220 my.mail.server.com Microsoft ESMTP MAIL Service ready at Thu, 26 Au
g 2010 08:03:09 -0700
EHLO
250-my.mail.server.com Hello [123.123.123.123]
250-SIZE 52428800
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-AUTH
250-8BITMIME
250-BINARYMIME
250 CHUNKING
STARTTT
500 5.3.3 Unrecognized command
STARTTLS
220 2.0.0 SMTP server ready
0
 

Author Comment

by:Dean_Kletter
ID: 33532558
I tried entering my email and password to log in in but received nothing after either carriage return...
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33532637
You didn't follow all the instructions.

EHLO put.your.server.name.here
STARTTLS
EHLO put.your.server.name.here


You have to say EHLO again once you've STARTTLS

EHLO (the second one) should now show you what AUTH options you've got.

0
 

Author Comment

by:Dean_Kletter
ID: 33532681
:D, that would be my bad...

Ok, I did it and the second one does the same thing, it just sits there at the next carriage return
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33532686
http://qmail.jms1.net/test-auth.shtml has some more useful notes about how to build the username/password.

You never put it in in real plain text, always encoded.

As you can see from the link ...

"Sending the AUTH command

Assuming the server supports AUTH, we will send the actual AUTH command to try and authenticate.

AUTH PLAIN AGptczFAam1zMS5uZXQAbm90Lm15LnJlYWwucGFzc3dvcmQ=
235 ok, go ahead (#2.0.0)"

The is ...

php -r "echo base64_decode('AGptczFAam1zMS5uZXQAbm90Lm15LnJlYWwucGFzc3dvcmQ=');"

 jms1@jms1.net not.my.real.password

The character before the username and the password is NOT a space, but a \000

e.g.

php -r "echo base64_encode(chr(0) . 'jms1@jms1.net' . chr(0) . 'not.my.real.password');"

outputs ...

AGptczFAam1zMS5uZXQAbm90Lm15LnJlYWwucGFzc3dvcmQ=
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33532692
So, entering EHLO the second time didn't produce ANY response?
0
 

Author Comment

by:Dean_Kletter
ID: 33532761
entering EHLO 2nd time produced no results...  so you're saying I need to enter the AUTH PLAIN encoded plain text after I get 220 2.0.0 smtp server ready?

Can I use the tool provided by the first link you gave me?  And I'm not understanding this space between the email and password is a \000.  I'm assuming your second php example is what correct this and am wondering where I enter this php command?  into my php email code?
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33532786
Can you re-try the PHP script.

Add ..

$mail->SMTPSecure = 'tls';

to the setup part.

Keep the debugging in.

What output now?
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33532824
That was a command line script.

C:\php5\php.exe -r "echo base64_encode(chr(0) . 'RQuadling@e-e.com' . chr(0) . 'NotLikelySonnyJim');"

outputs ...

AFJRdWFkbGluZ0BlLWUuY29tAE5vdExpa2VseVNvbm55Smlt

So that would be the string to use. As in ...

AUTH PLAIN AFJRdWFkbGluZ0BlLWUuY29tAE5vdExpa2VseVNvbm55Smlt

sort of thing.

0
 

Author Comment

by:Dean_Kletter
ID: 33532855
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 my.mail.server.com Microsoft ESMTP MAIL Service ready at Thu, 26 Aug 2010 08:27:11 -0700 "
SMTP -> get_lines(): $data is "220 my.mail.server.com Microsoft ESMTP MAIL Service ready at Thu, 26 Aug 2010 08:27:11 -0700 "
SMTP -> FROM SERVER:220 my.mail.server.com Microsoft ESMTP MAIL Service ready at Thu, 26 Aug 2010 08:27:11 -0700
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-my.mail.server.com Hello [123.123.123.123] "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] "
SMTP -> get_lines(): $str is "250-SIZE 52428800 "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 "
SMTP -> get_lines(): $str is "250-PIPELINING "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING "
SMTP -> get_lines(): $str is "250-DSN "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $str is "250-STARTTLS "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS "
SMTP -> get_lines(): $str is "250-AUTH "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH "
SMTP -> get_lines(): $str is "250-8BITMIME "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME "
SMTP -> get_lines(): $str is "250-BINARYMIME "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $data was "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $str is "250 CHUNKING "
SMTP -> get_lines(): $data is "250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME 250 CHUNKING "
SMTP -> FROM SERVER: 250-my.mail.server.com Hello [123.123.123.123] 250-SIZE 52428800 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME 250 CHUNKING
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 2.0.0 SMTP server ready "
SMTP -> get_lines(): $data is "220 2.0.0 SMTP server ready "
SMTP -> FROM SERVER:220 2.0.0 SMTP server ready

Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\WWW\mydomain.com\class.smtp.php on line 197
SMTP -> FROM SERVER:
SMTP -> ERROR: RSET failed:
Language string failed to load: tls
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Dean_Kletter
ID: 33533112
The first line is 197 from the file referenced.

if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
      return false;
    }

    return true;
  }
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 33533170
The specification says the mechanism is not optional, but your server is telling you there are no mechanisms.  The "250-AUTH" response should be something like "250-AUTH PLAIN LOGIN MD5".  In other words, a space-delimited list of the valid mechanism the server allows.  STARTTLS is an optional step, and the list of mechanisms can change after you start a TLS session.

Can your host show you a working example of an AUTH conversation from their end?

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 33533198
0
 

Author Comment

by:Dean_Kletter
ID: 33533277
checking now with them...
0
 

Author Comment

by:Dean_Kletter
ID: 33534011
ok, that was a total waste of time and my life.  There basic answer is this, if outlook works there isn't a problem and its your code.  Super.  

Interestingly, I tried a pop3 mail php script and got an error.  However I did find this line:

AUTH 250-8BITMIME

I tried again after manually adding port 110 to host name and got this instead... feels like I'm getting closer if I just focus on using pop3.

Server reported an error: -ERR Command is not valid in this state.
0

Could not access file: images/phpmailer.gif Could not access file: images/phpmailer_mini.gif SMTP -> FROM SERVER:+OK The Microsoft Exchange POP3 service is ready.
SMTP -> FROM SERVER: -ERR Protocol error. 19 -ERR Connection is closed. 12
SMTP -> ERROR: EHLO not accepted from server: -ERR Protocol error. 19 -ERR Connection is closed. 12
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedThe following From address failed: my@email.com Mailer Error: The following From address failed: myemail@email.com
0
 

Author Comment

by:Dean_Kletter
ID: 33534030
here the code....
<html>

<head>

<title>POP before SMTP Test</title>

</head>

<body>



<?php

require_once('class.phpmailer.php');

require_once('class.pop3.php'); // required for POP before SMTP



$pop = new POP3();

$pop->Authorise('my.mail.server.com', 110, 25, 'my@email.com', 'password123', 1);



$mail = new PHPMailer();



$body             = 'test';

$body             = eregi_replace("[\]",'',$body);



$mail->IsSMTP();

$mail->SMTPDebug = 2;



$mail->Host     = 'my.mail.server.com:110';



$mail->SetFrom('my@email.com', 'First Last');



$mail->AddReplyTo("my@email.com","First Last");



$mail->Subject    = "PHPMailer Test Subject via POP before SMTP, basic";



$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test



$mail->MsgHTML($body);



$address = "my@email.com";

$mail->AddAddress($address, "John Doe");



$mail->AddAttachment("images/phpmailer.gif");      // attachment

$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment





if(!$mail->Send()) {

  echo "Mailer Error: " . $mail->ErrorInfo;

} else {

  echo "Message sent!";

}



?>



</body>

</html>

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 33538040
POP3 is not SMTP.  POP3 is how a remote user receives messages.  SMTP is used to send them.  Some servers do support POP-SMTP, which is essentially having the remote user log in and check their mail (POP3) immediately before attempting to send (SMTP).  Your host may be relying solely on this mechanism for authentication to send.

If your host is basing "it works" solely on the functionality of Outlook, they are not a very good host and should be replaced.  Any tech who attempts to send through an authenticated SMTP session using telnet will be able identify this issue.  The fix is usually just a flag or configuration item on the server side, and SMTP AUTH is standard enough that there is no reason to not support it.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33540206
Outlook does NOT use SMTP.

Outlook uses Extended MAPI to talk to Exchange Server. A completely different protocol.

If you want to go down that route, then the easiest way is to use Outlook Redemption - an COM library capable of talking to Exchange just like Outlook. If Outlook can do it, then Redemption can.

Downside? You need to be using Windows. And you have to learn COM and the Outlook object model and .... well, the list will go on I'm sure.

If you are sending messages to 1 recipient, then you have the option of bypassing your local SMTP Relay and sending the message directly. Just like a spam-bot would do.

How?

Easy.

Extract the domain from the recipient's email address.
Use getmxrr() to find the MX record and appropriate hosts.
Use PHPMailer to send the email to the host for the recipient.

No authentication is necessary as you are NOT relaying. This, in essence, is what a relay would do.

Not a perfect solution admittedly. You may not get access as you are not a real, identifiable, mail engine. You are just a PHP script. (If you see what I mean).

But, if they have their web server and their SMTP relay on the same IP, then reverse DNS lookup of the sending machine will be the same. I think this is one way to get things working. But I'm not an expert on bypassing things like this, sorry.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 33548126
>>> Not a perfect solution admittedly. You may not get access as you are not a real, identifiable, mail engine.

To explain more about RQuadling's caveats, you will most likely fail DomainKey or SPF validation.  While what he suggests is technically possible, it probably is not a good idea for a long term solution.  Many email providers report attempts such as those to black lists, and some of those are notorious for the difficulty involved in getting removed.

I would go back to the provider again and have try the telnet experiment.  If they cannot show you a successful authentication and send through telnet, then their service is not working as advertised.  Either that, or find a new provider.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33548723
Have you tried NOT using authentication?

And remember Outlook does NOT use SMTP, so their comments about "if Outlook works ..." is not applicable.

0
 

Author Comment

by:Dean_Kletter
ID: 33572655
Ok, sorry for the delay but in response to this I set up a spare server with a new Windows Server 2008 and Exchange 2010 to test as a new mail server for the organization.  I'm having the same issue so I will post another questions in an attempt to get this moving.  I'm having the same issue with the telnet session freezing at the AUTH attempt.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33574662
What happens if you DON'T AUTH? It looks like your server doesn't have any AUTH mechanisms. Which is odd. But that what it looks like.

So don't auth.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 33574825
I agree with RQuadling - it looks like they have disabled AUTH.  According to this link:

http://itknowledgeexchange.techtarget.com/itanswers/i-need-help-with-exchange-2003-authentication-through-telnet/

Exchange supports three types of SMTP authentication, and none of them are showing up in your server responses.  That means they are probably limiting their relay ability to SMTP-after-POP.  Try a telnet test by connecting to the server with POP to list new messages.  Then logoff POP, and try an SMTP session without AUTH.  Post your results here.  Timing will be an issue, so try it a couple times until you are comfortable with making it happen quickly.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33574970
@routinet : Thanks for the added interpretation - Exchange is one of my weak points.
0
 

Author Comment

by:Dean_Kletter
ID: 33577355
Thanks guys, but I am now testing this script on a brand spanking new Exchange 2010 server with the same results.  I most certainly have authorization enabled on my smtp receive connector but for some reason when I type the AUTH command nothing is given in response?
0
 

Author Comment

by:Dean_Kletter
ID: 33577520
This is what I'm getting when I run my php script.  I'll try the pop3 before smtp suggestion and post results.  Any idea on what my authorization and permission group setting "should" be on my default smtp receive connector?
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 MAIL.mydomain.COM "
SMTP -> get_lines(): $data is "220 MAIL.mydomain.COM "
SMTP -> FROM SERVER:220 MAIL.mydomain.COM
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-MAIL.mydomain.COM Hello [123.123.123.123] "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] "
SMTP -> get_lines(): $str is "250-SIZE "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE "
SMTP -> get_lines(): $str is "250-PIPELINING "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING "
SMTP -> get_lines(): $str is "250-DSN "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN "
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $str is "250-STARTTLS "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS "
SMTP -> get_lines(): $str is "250-AUTH NTLM "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH NTLM "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH NTLM "
SMTP -> get_lines(): $str is "250-8BITMIME "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH NTLM 250-8BITMIME "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH NTLM 250-8BITMIME "
SMTP -> get_lines(): $str is "250-BINARYMIME "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH NTLM 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $data was "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH NTLM 250-8BITMIME 250-BINARYMIME "
SMTP -> get_lines(): $str is "250 CHUNKING "
SMTP -> get_lines(): $data is "250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH NTLM 250-8BITMIME 250-BINARYMIME 250 CHUNKING "
SMTP -> FROM SERVER: 250-MAIL.mydomain.COM Hello [123.123.123.123] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH NTLM 250-8BITMIME 250-BINARYMIME 250 CHUNKING
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "504 5.7.4 Unrecognized authentication type "
SMTP -> get_lines(): $data is "504 5.7.4 Unrecognized authentication type "
SMTP -> ERROR: AUTH not accepted from server: 504 5.7.4 Unrecognized authentication type
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 2.0.0 Resetting "
SMTP -> get_lines(): $data is "250 2.0.0 Resetting "
SMTP -> FROM SERVER:250 2.0.0 Resetting
SMTP Error: Could not authenticate.

Open in new window

0
 
LVL 40

Accepted Solution

by:
RQuadling earned 250 total points
ID: 33577936
Follow http://www.yuki-onna.co.uk/email/smtp.html

Changing the domain name and HELO to EHLO.

Basically YOU type.

EHLO your-machine
MAIL FROM: mail@domain.ext
RCPT TO: mail@otherdomain.ext
DATA
Subject:-type subject here-
hello mail@otherdomain.ext from mail@domain.ext
.

QUIT

(I think).


0
 

Author Comment

by:Dean_Kletter
ID: 33578198
It gives the 530 5.7.1 Client was not authenticated error right after I enter mail from
0
 
LVL 50

Assisted Solution

by:Steve Bink
Steve Bink earned 250 total points
ID: 33584383
RQuadling is absolutely on the ball with EHLO vs HELO.  EHLO tells the server to expect extended commands, not just the original SMTP verbs.  Two additional items:

1) I don't see your transmissions in that debug output.  Have you tried this from a telnet conversation?  Do you have access to the raw SMTP log kept on the server?  The PHP debugging output is great for debugging the code, but this issue does not appear to lie in the code.

2) Typing "AUTH" to the server is done *after* you already know what kind of AUTH it accepts.  Your server response to the HELO/EHLO in that last example shows:

250-AUTH NTLM

That response indicates the server is set to accept only NTLM authentication.  Another way of saying that is "integrated Windows authentication".  You need to change it to use plain-text (LOGIN is 64-bit encoded, but still a plain-text method of transmission).  See this link for Exchange 2003.  If you have a newer version, it will probably be similar:

http://www.changeip.com/at/kb-print/47.html

I'm not very familiar with Exchange either, so I think we're feeling our way a bit blind.  :)  The link shows that you can only have plain-text *or* NTLM, which does not make a lot of sense considering other sample conversations I have seen (sample in which AUTH PLAIN LOGIN NTLM is in the EHLO response).  There must be a way to light up both at once.  
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 33584398
Here is another good link for Exchange 2007 (in SBS, I think), which is apparently pretty different:

http://www.petri.co.il/authenticated-or-anonymous-smtp-relay-with-exchange-2007.htm

It looks like 2007 also addressed the either-or situation I mentioned.  Now the options are checkboxes instead of radio buttons.
0
 

Author Closing Comment

by:Dean_Kletter
ID: 33607355
Ok, once I shifted to port 587 and i adjusted the permissions group I was able to successfully use the script.  I had an smtp connector issue which was hampering the PHP code.

Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now