GMail Authentication 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
abumgardner
Forum Newbie
Posts: 2
Joined: Fri Nov 02, 2007 10:38 pm

GMail Authentication Failure

Post by abumgardner »

I am encountering an authentication error when trying to send an email via SwiftMailer using the GMail SMTP servers. I am using the following:
PHP5
Swift 3.3.2-php5
Apache HTTP 2.2

Code: Select all

require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";

$smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$smtp->setUsername("mygmailaccount@gmail.com");
$smtp->setpassword("mypassword");
 
$swift =& new Swift($smtp);
Here is the exception that is thrown:
Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'Authentication failed using username 'mygmailaccount@gmail.com' and password '********'' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lib\Swift\Connection\SMTP.php:414 Stack trace: #0 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lib\Swift\Connection\SMTP.php(331): Swift_Connection_SMTP->runAuthenticators('mygmailaccount@gma...', 'mypass', Object(Swift)) #1 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lib\Swift.php(264): Swift_Connection_SMTP->postConnect(Object(Swift)) #2 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lib\Swift.php(220): Swift->handshake(Object(Swift_Events_ResponseEvent)) #3 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lib\Swift.php(101): Swift->connect() #4 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\handle_form.php(54): Swift->__construct(Object(Swift_Connection_SMTP)) #5 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lib\Swift\Connection\SMTP.php on line 414
I also tried explicitly setting the different Authenticators, CRAMMD5, LOGIN and PLAIN. I know if you don't set them they should all load automatically but I was trying anything.

Is there something special you have to do to work with GMail? I have checked and triple checked the username and password.


---EDIT
I went back and turned on the logging and here is the response:
++ 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 'tls://smtp.gmail.com:465 << 220 mx.google.com ESMTP 22sm2796321nzn >> EHLO [127.0.0.1] << 250-mx.google.com at your service, [76.177.184.170] 250-SIZE 28311552 250-8BITMIME 250-AUTH LOGIN PLAIN 250 ENHANCEDSTATUSCODES ++ SMTP extension 'SIZE' reported with attributes [28311552]. ++ SMTP extension '8BITMIME' reported with attributes []. ++ SMTP extension 'AUTH' reported with attributes [LOGIN, PLAIN]. ++ SMTP extension 'ENHANCEDSTATUSCODES' reported with attributes []. ++ Trying to authenticate with username 'mygmailaccount@gmail.com'. ++ No authenticators loaded; looking for defaults. ++ Authentication mechanism 'CRAM-MD5' attached. ++ Authentication mechanism 'LOGIN' attached. ++ Authentication mechanism 'PLAIN' attached. ++ Trying 'LOGIN' authentication... >> AUTH LOGIN << 334 VXasfasfjU6 >> YWalksjdfkjiieupihh29t << 334 UGasdfadfQ6 >> egmwVyfasd8= << 535 5.7.1 Credentials Rejected 22sppojknKhl;qnzn !! Expected response code(s) [235] but got response [535 5.7.1 Credentials Rejected 22sm989823421nzn] >> RSET << 250 2.1.0 Flushed 22sm2796321nzn ++ Trying 'PLAIN' authentication... >> AUTH PLAIN YWJ1bWdhcmRuZXlsowojk;hwiuuoahhasmNvbQB6ZXJvZ2F4bw== << 535 5.7.1 Credentials Rejected 22sm2796123nzn !! Expected response code(s) [235] but got response [535 5.7.1 Credentials Rejected 22sm2796123nzn] >> RSET << 250 2.1.0 Flushed 22sm2796123nzn
---EDIT

Any help would be appreciated.

Thanks
abumgardner
Forum Newbie
Posts: 2
Joined: Fri Nov 02, 2007 10:38 pm

Post by abumgardner »

Please disregard.

It must have been late. I changed my gmail password and then adjusted the code and it works. I had to have had something misspelled.

Thanks
Post Reply