【发布时间】:2014-12-27 07:32:25
【问题描述】:
虽然我尝试通过引用 RAILSCAST #247 添加“忘记密码”功能,但错误消息“我们很抱歉,但出了点问题。”在生产环境(不是 Heroku)的浏览器上显示。
访问下面的链接后发生了同样的错误。 http://www.google.com/accounts/DisplayUnlockCaptcha 和 https://www.google.com/settings/security/lesssecureapps
stdout.log 如下;
Started POST "/password_resets" for 12.345.67.89 at 2014-12-27 09:10:24 +0000
Processing by PasswordResetsController#create as HTML
Parameters: {"utf8"=>"?", "authenticity_token"=>"xxx", "email"=>"xxx@xxx.com", "commit"=>"reset PW"}
Rendered user_mailer/password_reset.text.erb (1.1ms)
Sent mail to xxx@xxx.com (1617.4ms)
Completed 500 Internal Server Error in 1775ms
Net::SMTPAuthenticationError (534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=xxx
):
app/models/user.rb:36:in `send_password_reset'
app/controllers/password_resets_controller.rb:6:in `create'
导致错误的这些文件的内容如下。
\app\models\user.rb
class User < ActiveRecord::Base
.
.
def send_password_reset
generate_token(:password_reset_token)
self.password_reset_sent_at = Time.zone.now
save!(validate: false)
UserMailer.password_reset(self).deliver #line 36
end
.
.
\app\controllers\password_resets_controller.rb
class PasswordResetsController < ApplicationController
.
.
def create
user = User.find_by_email(params[:email])
user.send_password_reset if user #line 6
redirect_to root_url, :notice => "Email sent with password reset instructions."
end
.
.
我在 production.rb 中添加了一些设置以通过参考 RailsGuides 来使用 Gmail。
\config\environments\production.rb
.
.
config.action_mailer.default_url_options = { :host => 'example.com' } #change to hosting setting
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'example.com', #change to hosting setting
:user_name => 'xxx@gmail.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true }
.
.
请告诉我如何避免这个错误。
【问题讨论】:
-
google mail 默认阻止 smtp auth,尝试在设置 gmail 帐户中找到有关此的内容。
-
感谢您的建议,@Зелёны。它按原样工作。好像反射
UnlockCaptcha或lesssecureapps花了很长时间。
标签: ruby-on-rails ruby ruby-on-rails-4 heroku gmail