SMTP auth failure

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
zoi
Forum Newbie
Posts: 3
Joined: Fri Sep 28, 2007 4:17 pm

SMTP auth failure

Post by zoi »

I'm having problems with SMTP authentication.

Redhat Fedora
Apache 2.2.2
PHP 5.1.6
SwiftMailer 3.3.1
ESMTP Sendmail 8.13.8/8.13.5

sendmail:

Code: Select all

250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
the script

Code: Select all

$message = new Swift_Message($sSubject, $sMessage, "text/html");
        $log = Swift_LogContainer::getLog();
        $log->setLogLevel(4);

try {
            $smtp = new Swift_Connection_SMTP("1www", 25);            

            $smtp->setUsername("foo");
            $smtp->setpassword("bar");

            $swift = new Swift($smtp);

            $log = Swift_LogContainer::getLog();
            echo $log->dump(true);
        }
        catch (Swift_ConnectionException $e) {
            echo "There was a problem communicating with SMTP: " . $e->getMessage();
        } catch (Swift_Message_MimeException $e) {
            echo "There was an unexpected problem building the email:" . $e->getMessage();
        }

        if ($swift->send($message, $sFriendEmail, "foo@novaraja.com"))
        {
            echo "Message sent";
        }
        else
        {
            echo "Message not sent!";
        }

        $swift->disconnect();
log dump

Code: Select all

++ Log level changed to 4
++ Forcing ESMTP mode.  HELO is EHLO.
++ Forcing ESMTP mode.  HELO is EHLO.
++ Trying to connect...
++ Trying to connect to SMTP server at '1www:25
<< 220 www.novaraja.com ESMTP Sendmail 8.13.8/8.13.5; Fri, 28 Sep 2007 23:32:44 +0200
>> EHLO [217.198.148.239]
<< 250-www.novaraja.com Hello 2www [217.198.148.239], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
++ SMTP extension 'ENHANCEDSTATUSCODES' reported with attributes [].
++ SMTP extension 'PIPELINING' reported with attributes [].
++ SMTP extension '8BITMIME' reported with attributes [].
++ SMTP extension 'SIZE' reported with attributes [].
++ SMTP extension 'DSN' reported with attributes [].
++ SMTP extension 'AUTH' reported with attributes [DIGEST-MD5, CRAM-MD5].
++ SMTP extension 'DELIVERBY' reported with attributes [].
++ SMTP extension 'HELP' reported with attributes [].
++ Trying to authenticate with username 'registracija'.
++ No authenticators loaded; looking for defaults.
++ Authentication mechanism 'CRAM-MD5' attached.
++ Authentication mechanism 'LOGIN' attached.
++ Authentication mechanism 'PLAIN' attached.
++ Trying 'CRAM-MD5' authentication...
>> AUTH CRAM-MD5
<< 334 PDMyMjQ1MDk0MDAuMTY2MTAxMTRAd3d3Lm5vdmFyYWphLmNvbT4=
>> cmVnaXN0cmFjaWphIDg2ODBkMDUzNTJhMDUxYjgxZTg0OGEwYThhOWQ3YTAy
<< 535 5.7.0 authentication failed
!! Expected response code(s) [235] but got response [535 5.7.0 authentication failed]
>> RSET
<< 250 2.0.0 Reset state
..and yes, the username and password are correct ...I can send emails through a webmail client (using the same smtp) thought:)

The handshake procedure goes well and swift returns hashed string but still...something is wrong :/

Do I have to alter sendmail conf file in order to make it work?

cheers
chuckl
Forum Commoner
Posts: 61
Joined: Wed May 23, 2007 7:36 am

Post by chuckl »

For authenticated login, your SMTP server offers DIGEST-MD5 or CRAM-MD5 authentication.

You should load the required Swift Authenticator in your code

Code: Select all

$smtp->attachAuthenticator(new Swift_Authenticator_CRAMMD5());
immediately after your

Code: Select all

$smtp = new Swift_Connection_SMTP("1www", 25);
zoi
Forum Newbie
Posts: 3
Joined: Fri Sep 28, 2007 4:17 pm

Post by zoi »

chuckl wrote:For authenticated login, your SMTP server offers DIGEST-MD5 or CRAM-MD5 authentication.

You should load the required Swift Authenticator in your code

Code: Select all

$smtp->attachAuthenticator(new Swift_Authenticator_CRAMMD5());
immediately after your

Code: Select all

$smtp = new Swift_Connection_SMTP("1www", 25);
According to Swift docs, this should happen automatic, and it does (see log):

Code: Select all

++ Authentication mechanism 'CRAM-MD5' attached.
++ Authentication mechanism 'LOGIN' attached.
++ Authentication mechanism 'PLAIN' attached.
++ Trying 'CRAM-MD5' authentication...
..and the hash is sent back to smtp

Code: Select all

>> cmVnaXN0cmFjaWphIDg2ODBkMDUzNTJhMDUxYjgxZTg0OGEwYThhOWQ3YTAy
<< 535 5.7.0 authentication failed
and fails :/
chuckl
Forum Commoner
Posts: 61
Joined: Wed May 23, 2007 7:36 am

Post by chuckl »

I know the documentation says that the auth plugins are loaded automatically etc. I was suggesting that when you are having a problem, don't trust 'automatically' , but load it explicitily.

Doesn't alter the fact that the server is returning a 535 error. Not Swiftmailer, but the server is saying. 'Authentication failure, incorrect username or password'.
zoi
Forum Newbie
Posts: 3
Joined: Fri Sep 28, 2007 4:17 pm

Post by zoi »

chuckl wrote:I know the documentation says that the auth plugins are loaded automatically etc. I was suggesting that when you are having a problem, don't trust 'automatically' , but load it explicitily.
Yes, I already tried that before I found out that it can load req auth class automatic.
Doesn't alter the fact that the server is returning a 535 error. Not Swiftmailer, but the server is saying. 'Authentication failure, incorrect username or password'.

Username and password have been tested and are 100% correct. I've even changed the password several times for testing purpose, but still that didn't work out :/, and I've tested to log from several e-mail clients and it works (maybe the clients are using digest auth instead of cram?..). I'm trying to isolate the problem here, and I too believe that something is wrong on the smtp side and not with Swift it self. I'll try to add PLAIN auth to smtp and test if that works.
Post Reply