相关文章推荐
烦恼的跑步鞋  ·  sql ...·  2 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted

Ask Question

I recently encountered a SwiftMail error while trying to send a mail through gmail.

 Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted.

I was trying to send mail through my gmail and google thought that I was a spam(maybe because I was requesting too fast) I received a mail from them saying my account was access and I told them it was me. I was able to send mail without problem and it just occured now.

This is the contents of my env file.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=talentscoutphil@gmail.com
MAIL_PASSWORD=mypasswordhere
MAIL_FROM=talentscoutphil@gmail.com
MAIL_NAME=talentscout

I researched on the internet and some answers includes enabling the "access for lesser app" and "unlocking gmail captcha" which sadly didn't work for me until I found the 2-step verification.

What I did the following was:

  • enable the 2-step verification to google HERE

  • Create App Password to be use by your system HERE

  • I selected Others (custom name) and clicked generate

  • Went to my env file in laravel and edited this

    MAIL_USERNAME=talentscoutphil@gmail.com

    MAIL_PASSWORD=thepasswordgenerated

  • Restarted my apache server and boom! It works again.
  • This was my solution. I created this to atleast make other people not go wasting their time researching for a possible answer.

    I follow step by step but can't get it working. Please share your other variables (for example encryption, port). – JCarlosR Jun 20, 2017 at 1:49 I answer to myself. Encryption tls, port 587. But most importantly: php artisan config:cache to update the env variables! – JCarlosR Jun 20, 2017 at 2:02 I did exactly these steps and solved my problem. After using app password, I disabled 2 step verification, and it still works. – Imtiaz Sep 4, 2018 at 1:13 Work for me in Symfony 4.3 . The error was: app.ERROR: Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "xxxxxx" using 2 possible authenticators. Authenticator LOGIN ........... Username and Password not accepted. – juanitourquiza Sep 24, 2020 at 22:30

    I had everything fine. Less secure app option was also enabled. Still, I was getting the error. What I have done is:

  • Google will send you Critical security alert
  • Then you have to authorize that activity. ( Clicking on 'YES, THAT WAS ME' type thing )
  • Then you can try sending email again.
  • From May 30, 2022, ​​Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.

    Important: This deadline does not apply to Google Workspace or Google Cloud Identity customers. The enforcement date for these customers will be announced on the Workspace blog at a later date.

    For more information, continue to read. https://support.google.com/accounts/answer/6010255?hl=en&visit_id=637919157823422324-2612210762&p=less-secure-apps&rd=1

    i was getting thesame error as stated in the question but by using

    php artisan config:cache
    

    Everything worked fine

    Gmail tends to block usage of mailing addresses which are being used in other applications as username for security reasons. Either you should create a new email address for mail purpose or you must go to the Less Secure App Access and turn on the access for less secure apps. Gmail will send you a mail for confirmation from where you can verify that those changes were made by yourself. Only then, you can use such mailing addresses for mailing purpose through applications.

    There is no need to update anything in config/mail.php. just put you credential in .env with this specific key's. This is my .env file.

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=example@gmail.com
    MAIL_PASSWORD=********
    MAIL_ENCRYPTION=tls
    

    I had the same issue after long time debugging and googling i have found the solution. that by enabling less secure apps. the email started working.

    if your gmail is secure with 2 step verification you can't enable less secure app. so turn off 2 step verification and enable less secure app. by click here enable less secure apps on your gmail account

    This single step worked for me... No 2-step verification. As I had created a dummy account for my local development, so I was OK with this setting. Make sure you only do this if your account contains NO personal or any critical data. This is just another way of tackling this error and NOT secure.

    I turned ON the setting to alow less secured apps to be allowed access. Form here : https://myaccount.google.com/lesssecureapps

    Work for me in Symfony 4.3 . The error was: app.ERROR: Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "xxxxxx" using 2 possible authenticators. Authenticator LOGIN ........... Username and Password not accepted. – juanitourquiza Sep 24, 2020 at 22:29

    I encountered the same issue and solved it with no 2FA enabled ("Allow less secure apps" is still in need).

    After checking Google error code list, I thought maybe there are some errors in .env.

    Below settings are tested in Laravel 8 and worked:

    MAIL_MAILER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=username@gmail.com
    MAIL_PASSWORD='your#password_here'  # put the password in quotes
    MAIL_ENCRYPTION=tls
    MAIL_FROM_ADDRESS=username@gmail.com
    MAIL_FROM_NAME="${APP_NAME}"
    

    Please remember that put the password in quotes. That works for me.

    The password in quotes worked, you also need to do the following: php artisan config: cache – Nuril Dec 6, 2021 at 9:36

    As from May 30, 2022 Google has stopped the support of third-party apps or devices which ask you to signin to your Google Account using only your username and password.

    To solve this,

  • make sure you that you have enabled 2-step verification.
  • Then select App paswords.
  • select app and device you want to generate the app password for.
  • on select app select mail then on device choose and name a custom device.
  • After that, a password will be generated for you to use. Replace your original password with the generated password. Refresh or upload your files to the server the reload. It will work
  •