【问题标题】:Cannot send email from Yii SwiftMail to GMail: Expected response code 250 but got code "535"无法从 Yii SwiftMail 向 GMail 发送电子邮件:预期响应代码为 250,但得到代码“535”
【发布时间】:2016-05-18 04:16:04
【问题描述】:

我收到此错误代码:

预期的响应代码为 250,但得到代码“535”,消息“535-5.7.8 用户名和密码不被接受。了解更多信息,请访问 535 5.7.8 https://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, 有人刚刚尝试通过不符合现代安全标准的应用登录您的 Google 帐户 contact@xxxxxxxx.com。 细节: 2016 年 5 月 17 日星期二 23:27(东部夏令时间) 美国弗吉尼亚州阿什本* 我们强烈建议您使用安全的应用程序(例如 Gmail)来访问您的帐户。 Google 制作的所有应用都符合这些安全标准。另一方面,使用安全性较低的应用程序可能会使您的帐户容易受到攻击。了解更多。

Google 已停止此登录尝试,但您应该检查您最近使用的设备

Yii 文档说 'tls' 是一个选项。 http://www.yiiframework.com/doc-2.0/yii-swiftmailer-mailer.html

是的,我验证了解密后的值是正确的密码。我已经访问过https://accounts.google.com/DisplayUnlockCaptcha。我无法打开 2-factor,因为我不拥有该帐户并且它需要一个电话号码。我现在无法打开“允许不安全访问”,因为它是客户的帐户,但我已经问过了。 (不过,我宁愿不允许不安全的访问。)

【问题讨论】:

    标签: php email yii2 gmail


    【解决方案1】:
       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
    
    
        
    

    【讨论】:

      【解决方案2】:

      首先,在加密中使用ssl,在端口中使用465,因为 两因素身份验证中的不使用您的 gmail 密码, 但创建一个 gmail APP 密码,以便更好地访问 从那里到不太安全的应用程序,这里是the link 创建应用密码。

      【讨论】:

        【解决方案3】:

        嘿,经过几个小时的研究,给你一些建议:

        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,
                ],
            ],
        
        

        【讨论】:

        • 我认为你应该验证谷歌的 SSL 证书,它也不会是自签名的。
        【解决方案4】:

        试试

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

        【讨论】:

        • 对不起,它仍然失败并显示相同的错误消息。
        【解决方案5】:

        您必须登录您的 gmail 帐户并进入安全设置并通知他们您正在尝试访问您的帐户。因为它看起来很可疑,所以他们把它挡住了。

        转到this link,然后重试。

        【讨论】:

          猜你喜欢
          • 2018-09-10
          • 2016-04-11
          • 2017-07-23
          • 2017-07-22
          • 2021-02-02
          • 1970-01-01
          • 1970-01-01
          • 2016-08-14
          • 2015-09-16
          相关资源
          最近更新 更多