Ruby-on-rails 535-5.7.8 不接受用户名和密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23137012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:33:32  来源:igfitidea点击:

535-5.7.8 Username and Password not accepted

ruby-on-rails

提问by xps15z

I have a contact form and after submitting I am getting a Net::SMTPAuthenticationError 535-5.7.8 Username and Password not accepted

我有一个联系表格,提交后我收到 Net::SMTPAuthenticationError 535-5.7.8 Username and Password not accepted

It's pointing to the create action in the contacts controller ContactMailer.new_contact(@contact).deliver

它指向联系人控制器中的创建操作 ContactMailer.new_contact(@contact).deliver

I have restarted the server. I tried https://accounts.google.com/DisplayUnlockCaptcha.

我已经重新启动了服务器。我试过https://accounts.google.com/DisplayUnlockCaptcha

I am in development.

我正在开发中。

Contacts controller:

联系人控制器:

 def new
      @contact = Contact.new
    end

    def create
      @contact = Contact.new(params[:message])
      if @contact.valid?
        ContactMailer.new_contact(@contact).deliver
        flash[:notice] = "Message sent! Thank you for contacting us."
        redirect_to root_url
      else
        render :action => 'new'
      end
    end
  end

Development.rb:

开发.rb:

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            '[email protected]',
    password:             'password',
    authentication:       'plain',
    enable_starttls_auto: true  }

  config.action_mailer.default_url_options = { :host => "localhost:3000" }

采纳答案by MrYoshiji

First, You need to use a valid Gmail account with your credentials.

首先,您需要使用带有凭据的有效 Gmail 帐户。

Second, In my app I don't use TLS auto, try without this line:

其次,在我的应用程序中,我不使用 TLS auto,请尝试不使用此行:

config.action_mailer.smtp_settings = {
  address:              'smtp.gmail.com',
  port:                 587,
  domain:               'gmail.com',
  user_name:            '[email protected]',
  password:             'YOUR_PASSWORD',
  authentication:       'plain'
  # enable_starttls_auto: true
  # ^ ^ remove this option ^ ^
}


UPDATE: (See answer below for details) now you need to enable "less secure apps" on your Google Account

更新:(请参阅下面的答案了解详细信息)现在您需要在您的 Google 帐户中启用“安全性较低的应用”

https://myaccount.google.com/lesssecureapps?pli=1

https://myaccount.google.com/lesssecureapps?pli=1

回答by Ravindra Bhalothia

I had the same problem. Now its working fine after doing below changes.

我有同样的问题。现在在进行以下更改后工作正常。

https://www.google.com/settings/security/lesssecureapps

https://www.google.com/settings/security/lesssecureapps

You should change the "Access for less secure apps" to Enabled (it was enabled, I changed to disabled and than back to enabled). After a while I could send email.

您应该将“访问不太安全的应用程序”更改为“已启用”(它已启用,我更改为禁用,然后又重新启用)。过了一会儿,我可以发送电子邮件了。

回答by MrYoshiji

Goto config/initializers/setup_mail.rbCheck whether the configuration there matches the configuration written in the development.rbfile.It should look like the following in both files:

Gotoconfig/initializers/setup_mail.rb检查那里的配置是否与文件中写入的配置匹配development.rb。 两个文件中应该如下所示:

config.action_mailer.smtp_settings = {
     :address =>"[email protected]",
     :port => 587,
     :domain => "gmail.com",
     :user_name => "[email protected]",
     :password => "********",
     :authentication => 'plain',
     :enable_starttls_auto => true,
     :openssl_verify_mode => 'none' 
     } 

This will most certainly solve your problem.

这肯定会解决您的问题。

回答by BMA88

In my case removing 2 factor authentication solves my problem.

在我的情况下,删除 2 因素身份验证解决了我的问题。

回答by kryo

I did everything from visiting http://www.google.com/accounts/DisplayUnlockCaptchato setting up 2-fa and creating an application password. The only thing that worked was logging into http://mail.google.comand sending an email from the server itself.

我做了所有事情,从访问http://www.google.com/accounts/DisplayUnlockCaptcha到设置 2-fa 和创建应用程序密码。唯一有效的是登录http://mail.google.com并从服务器本身发送电子邮件。

回答by Sam Kah Chiin

If you still cannot solve the problem after you turn on the less secure apps. The other possible reason which might cause this error is you are not using gmail account.

如果开机后还是不能解决问题less secure apps。可能导致此错误的另一个可能原因是您没有使用 Gmail 帐户。

-    : user_name  =>  '[email protected]' ,  # It can not be used since it is not a gmail address 
+    : user_name  =>  '[email protected]' ,  # since it's a gmail address

Refer to here.

请参阅此处

Also, bear in mind that it might take some times to enable the less secure apps. I have to do it several times (before it works, every time I access the link it will shows that it is off) and wait for a while until it really work.

另外,请记住,启用less secure apps. 我必须做几次(在它起作用之前,每次我访问链接时它都会显示它是off)并等待一段时间直到它真正起作用。