Chloe
Chloe

Reputation: 26264

Cannot send email from Yii SwiftMail to GMail: Expected response code 250 but got code "535"

I got this error code:

Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/answer/14257

However, I'm using TLS so how could it possible be more secure?!

There are a few other questions, but they are not for Yii.

Some code:

Yii::$app->mailer->setTransport([
  'class' => 'Swift_SmtpTransport',
  'host' => BestSales::getConfigValue('smtp.host'),
  'username' => BestSales::getConfigValue('smtp.username'),
  'password' => BestSales::decrypt(BestSales::getConfigValue('smtp.password.encrypted')),
  'port' => BestSales::getConfigValue('smtp.port'),
  'encryption' => BestSales::getConfigValue('smtp.encryption'), // 'tls', 'ssl'
]);

Values:

[
    'smtp.host' => 'smtp.gmail.com',
    'smtp.username' => '[email protected]',
    'smtp.password.encrypted' => 'xxxxxxxxxxx',
    'smtp.port' => '587',
    'smtp.encryption' => 'tls',
]

I logged into Gmail and found this message:

Sign-in attempt prevented
Hi BestSales, Someone just tried to sign in to your Google Account [email protected] from an app that doesn't meet modern security standards. Details: Tuesday, 17 May 2016 23:27 (Eastern Daylight Time) Ashburn, VA, USA* We strongly recommend that you use a secure app, like Gmail, to access your account. All apps made by Google meet these security standards. Using a less secure app, on the other hand, could leave your account vulnerable. Learn more.

Google stopped this sign-in attempt, but you should review your recently used devices

The Yii docs says 'tls' is an option. http://www.yiiframework.com/doc-2.0/yii-swiftmailer-mailer.html

Yes, I verified the decrypted value is the correct password. I've already visited https://accounts.google.com/DisplayUnlockCaptcha. I can't turn on 2-factor because I don't own the account and it needs a phone number. I can't turn on 'allow insecure access' right now as it's a client's account, but I've asked. (I'd rather not allow insecure access though.)

Upvotes: 0

Views: 7826

Answers (5)

Nabin Rawat
Nabin Rawat

Reputation: 347

   1. Enable the 2-step verification
   2. Create App Passwdord to be use by your system HERE and use it 
   3. Now go to .env file and make these changes
        
        MAIL_DRIVER=smtp
        MAIL_HOST=smtp.gmail.com
        MAIL_PORT=587
        [email protected]
        MAIL_PASSWORD=password generated from app password
        MAIL_ENCRYPTION=tls
        
        This worked fine on mine.

    For 2-step verification 
       https://www.google.com/landing/2step/
    
    For App Password
       https://security.google.com/settings/security/apppasswords


    

Upvotes: 2

Kin
Kin

Reputation: 35

Hey after couple hours of resarching have some tips to you:

1 - Enable less security app access on gmail

2 - Access this link : https://www.google.com/accounts/DisplayUnlockCaptcha

3 - on config/web.php add these params:



        'encryption' => 'tls', 
        'streamOptions' => [
        'ssl' => [
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ],

Upvotes: 1

vasillis
vasillis

Reputation: 342

First of all, use ssl in encryption and value 465 in port, because of the two factor authentication do not use your gmail password, but create a gmail APP Password which is better to give access from there to a less secure application, here is the link for creating app passwords.

Upvotes: 1

Sukant Sharma
Sukant Sharma

Reputation: 1

You have to log into you gmail account and go the the security settings and notify them that it was you trying to access your account. They put a block on it because it looked suspicious.

Go to this link and try again.

Upvotes: -1

Alexandr Kalashnikov
Alexandr Kalashnikov

Reputation: 410

try

'smtp.port' => '465',
'smtp.encryption' => 'ssl',

Upvotes: 0

Related Questions