Laravel Gmail not working, "Username and Password not accepted. Learn more..."
Asked Answered
C

7

21

When I try to send an e-mail through my website running Laravel 4, I get this exception:

{"error":{"type":"Swift_TransportException","message":"Expected response code 250 but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 http:\/\/support.google.com\/mail\/bin\/answer.py?answer=14257 y70sm14744455qgd.3 - gsmtp\r\n\"","file":"\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Transport\/AbstractSmtpTransport.php","line":386}}

Here is my mail config:

return array(
  'driver' => 'smtp',
  'host' => 'smtp.gmail.com',
  'port' => 465,
  'from' => array('address' => '[email protected]', 'name' => 'myname'),
  'encryption' => 'ssl',
  'username' => '[email protected]',
  'password' => 'lol',
  'sendmail' => '/usr/sbin/sendmail -bs',
  'pretend' => false,
);

I've tried the disable link i've found by googling this issue except it didn't make a difference.

Is there a way to tell Google "stop blocking this IP, it's me" ?

Crutch answered 11/8, 2014 at 17:55 Comment(1)
I know this doesn't answer your question... but I would say don't use gmail for SMTP sending. Use a service like mandrill/mailgun... IE a service that is made for this type of thing. See my mandrill setup here: laravel.io/forum/… Mandrill gives you 12k emails free per month.Dandiprat
W
52

I tried the same thing and got the same error. So i personally checked my gmail account and i had a message from Gmail itself letting me know that they'd blocked an access attempt to my email account.

They showed an option to disable this security setting by visiting https://www.google.com/settings/security/lesssecureapps.

Things will actually be more straight forward if you visit that link already logged in into your Gmail account.

Warning

As @kodfire stated:

On May 30, 2022, this setting will no longer be available.

support.google.com/accounts?p=less-secure-apps&hl=en

Whelp answered 16/9, 2014 at 0:7 Comment(1)
On May 30, 2022, this setting will no longer be available. support.google.com/accounts?p=less-secure-apps&hl=enCapybara
O
32

Go to this link and disable unlock Captcha https://accounts.google.com/b/0/DisplayUnlockCaptcha

Oculo answered 5/10, 2014 at 16:4 Comment(1)
@trinity420 This is simply because Google blocked unsecure login to SMTP by default because for security.Oculo
M
14

Try this:

  1. Change port to 587
  2. Goto gmail setting https://www.google.com/settings/security/lesssecureapps and active it.
Matinee answered 29/12, 2014 at 7:17 Comment(0)
C
12

https://www.google.com/settings/security/lesssecureapps and active it. https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.

'port' => env('MAIL_PORT', 587), <br>
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
Cesarcesare answered 17/3, 2016 at 12:5 Comment(0)
L
8

I had lot of issues finding answer for this. Then after doing lot of trial and error i have found an solution to this. Most of the solution above worked for other but it help me upto 50%.

So, This is how it worked for me (100%):

  1. Activate 2 step Verification in google
  2. Now you will be able to create app. Open it.
  3. Create new app (other app) and give your app name.
  4. Now generate password.

Next in laravel, Goto .env file and change

    MAIL_USERNAME= 'App Name you created'
    MAIL_PASSWORD= 'Generated Password for that app'

This should be able to send emails from your gmail account. Please leave a comment if it doesn't works for you.

Lonnielonny answered 6/12, 2016 at 9:29 Comment(3)
I had a problem because I used username instead of 'username'Teatime
It is still giving me the same error Username and Password not accepted.Krupp
Works great. Just to correct that Username is not the app name but the email it self.Reinforce
A
3

Did you activate 2-step google authentification? If so, you need to define a new "application-specific password" password: http://www.google.com/landing/2step/.

Accounting answered 11/8, 2014 at 17:57 Comment(0)
C
-2

Remove the @gmail.com from username, already you mentioned smtp. So no need @gmail.com on your username. I'm 100% sure it is your problem, because I had that problem.

Collocate answered 4/4, 2019 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.