无法从Yii SwiftMail向GMail发送电子邮件:预期的响应代码为250,但得到的代码为“”;535”;


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

我得到了这个错误代码:

预期响应代码为250,但得到的代码为"535",并显示消息"535-5.7.8用户名和密码不被接受。有关详细信息,请访问535 5.7.8https://support.google.com/mail/answer/14257

然而,我正在使用TLS,所以它怎么可能更安全呢?!

还有一些其他的问题,但它们不适合Yii。

部分代码:

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'
]);

值:

[
    'smtp.host' => 'smtp.gmail.com',
    'smtp.username' => 'contact@xxxxxxxxxx.com',
    'smtp.password.encrypted' => 'xxxxxxxxxxx',
    'smtp.port' => '587',
    'smtp.encryption' => 'tls',
]

我登录了Gmail,发现了这条消息:

登录尝试被阻止
你好,BestSales,有人刚试图登录你的谷歌帐户contact@xxxxxxxx.com来自一个不符合现代安全标准的应用程序。详细信息:2016年5月17日,星期二23:27(东部夏令时)美国弗吉尼亚州阿什本*我们强烈建议您使用安全的应用程序,如Gmail,来访问您的帐户。谷歌制造的所有应用程序都符合这些安全标准。另一方面,使用不太安全的应用程序可能会使您的帐户易受攻击。了解更多信息。

谷歌停止了这种登录尝试,但你应该查看你最近使用的设备

Yii医生说"tls"是一种选择。http://www.yiiframework.com/doc-2.0/yii-swiftmailer-mailer.html

是的,我验证了解密后的值是正确的密码。我已经去过https://accounts.google.com/DisplayUnlockCaptcha.我不能打开双因素,因为我没有这个账户,它需要一个电话号码。我现在不能打开"允许不安全访问",因为这是客户的帐户,但我已经问过了。(不过我宁愿不允许不安全的访问。)

   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
        MAIL_USERNAME=youremail@gmail.com
        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

    

首先,在加密中使用ssl,在端口中使用值465,因为在双因素身份验证中,不要使用您的gmail密码,但创建一个gmail应用程序密码,这样更容易访问从那里到一个不太安全的应用程序,以下是创建应用程序密码。

嘿,经过几个小时的重新归档,有一些提示给你:

1-在gmail 上启用更少的安全应用程序访问

2-访问此链接:https://www.google.com/accounts/DisplayUnlockCaptcha

3-在config/web.php上添加这些参数:


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

尝试

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

您必须登录到您的gmail帐户,进入安全设置,并通知他们是您试图访问您的帐户。他们在上面加了块,因为它看起来可疑。

转到此链接,然后重试。