Ruby on rails 为什么我的身份验证电子邮件不起作用?我得到了一个;“身份验证错误”;
每当我重置密码或试图获得电子邮件确认时,我都会看到此类错误页面:Ruby on rails 为什么我的身份验证电子邮件不起作用?我得到了一个;“身份验证错误”;,ruby-on-rails,ruby,email,heroku,devise,Ruby On Rails,Ruby,Email,Heroku,Devise,每当我重置密码或试图获得电子邮件确认时,我都会看到此类错误页面: Net::smtpauthentication designe::passwords控制器#create中出现错误 我在Rails服务器日志中看到了这一点,看起来邮件正在发送,但是在邮件的底部,你可以看到我出现了某种错误 只有当我从development发送电子邮件身份验证时才会发生这种情况(我在下面包含了我的development.rb文件)。在Heroku上似乎效果很好 我已经在一个单独的.env文件中包含了我的电子邮件登录名
Net::smtpauthentication designe::passwords控制器#create中出现错误
我在Rails服务器日志中看到了这一点,看起来邮件正在发送,但是在邮件的底部,你可以看到我出现了某种错误
只有当我从development发送电子邮件身份验证时才会发生这种情况(我在下面包含了我的development.rb文件)。在Heroku上似乎效果很好
我已经在一个单独的.env文件中包含了我的电子邮件登录名,因此您不会在这里看到它,并且为了隐私起见,我已经在这些日志中更改了我的电子邮件地址
感谢您的帮助
Rails服务器日志:
(0.9ms) commit transaction
Rendered devise/mailer/confirmation_instructions.html.erb (1.1ms)
Sent mail to xx@xx.com (958.0ms)
Date: Wed, 23 Apr 2014 10:51:46 -0700
From: xx@xx.com
Reply-To: xx@xx.com
To: xx@xx.com
Message-ID: <5357fdb28f720_199810d2ab033cb@unknown20c9d07bac9b.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Welcome xx@xx.com!</p>
<p>You can confirm your account email through the link below:</p>
<p><a href="http://localhost:3000/users/confirmation?confirmation_token=ukG1PXbXyXP5LpjG1Eaa">Confirm my account</a></p>
Completed 500 Internal Server Error in 964ms
Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at
):
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/smtp.rb:948:in `check_response'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/smtp.rb:917:in `getok'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/smtp.rb:832:in `mailfrom'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/smtp.rb:659:in `send_message'
mail (2.5.4) lib/mail/network/delivery_methods/smtp.rb:113:in `block in deliver!'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/smtp.rb:520:in `start'
mail (2.5.4) lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
mail (2.5.4) lib/mail/message.rb:2129:in `do_delivery'
mail (2.5.4) lib/mail/message.rb:232:in `block in deliver'
actionmailer (4.0.0) lib/action_mailer/base.rb:456:in `block in deliver_mail'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionmailer (4.0.0) lib/action_mailer/base.rb:454:in `deliver_mail'
mail (2.5.4) lib/mail/message.rb:232:in `deliver'
devise (3.2.4) lib/devise/models/authenticatable.rb:173:in `send_devise_notification'
devise (3.2.4) lib/devise/models/confirmable.rb:102:in `send_confirmation_instructions'
devise (3.2.4) lib/devise/models/confirmable.rb:117:in `block in resend_confirmation_instructions'
devise (3.2.4) lib/devise/models/confirmable.rb:211:in `pending_any_confirmation'
devise (3.2.4) lib/devise/models/confirmable.rb:116:in `resend_confirmation_instructions'
devise (3.2.4) lib/devise/models/confirmable.rb:265:in `send_confirmation_instructions'
devise (3.2.4) app/controllers/devise/confirmations_controller.rb:9:in `create'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:423:in `_run__3176473197347058618__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/mapper.rb:44:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__455108311755261639__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.9ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.0ms)
Yoshirt::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Defining default url options for devise
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
# Change to true to allow email to be sent during development
# http://stackoverflow.com/questions/21610815/how-to-config-devise-gem-to-send-email-to-the-resource
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "mail.google.com",####important
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
end
您遵循了,看起来您的配置很好
因此,要么您的用户名/密码错误,要么您在进行这些配置更改后没有重新启动服务器?没有更多的错误消息了吗?根据与OP的聊天会话,没有从
.env
获取导致此错误的GMAIL\u用户名
和GMAIL\u密码
在development.rb中对用户名
和密码
进行硬编码非常有效
我强烈建议您使用gem,这是一种安全配置Rails应用程序的极好方法
另外,请阅读Daniel Kehoe和Taylor Mock在上的这篇优秀文章。您还可以了解如何在应用程序中使用figaro gem。您可以更改Gmail的安全性,并在中为不太安全的应用程序激活授权。对于发现此帖子但上述内容均无效的人,仅供参考邮件设置所在的development.rb在rails初始化过程的早期加载
我的解决方案:
我在config目录中创建了一个environment_variables.yml,并在那里添加了我的变量。我还向application.rb添加了这段代码,因为application.rb在development.rb之前加载
config.before_configuration do
env_file = Rails.root.join("config", 'environment_variables.yml').to_s
if File.exists?(env_file)
YAML.load_file(env_file)[Rails.env].each do |key, value|
ENV[key.to_s] = value
end # end YAML.load_file
end # end if File.exists?
end # end config.before_configuration
谢谢你看这个。。。用户名和密码是正确的,因为它似乎在我的远程项目上运行良好。我已更新了Rails服务器日志,以显示在发送电子邮件确认后发生的全部情况。。。有一句重复的话,读起来像“交付中的阻止”或“行动中的阻止”。我现在不确定这是什么意思。你说它在你的远程项目上运行良好,这是同一个项目吗?它只是在开发模式下无法在本地工作?对于仍有这些问题的人,请尝试在编辑配置后重新启动服务器,这样做,最终使事情正常工作!如果您的gmail帐户上有2步身份验证设置
,则您不能在此处使用原始密码。在这种情况下,您必须生成一个特定于应用程序的密码,并在您的config.action\u mailer.smtp\u设置中使用该密码。谢谢您提供的信息,因为稍后我可能需要它,但我不会对我的gmail帐户使用两步身份验证。让我们在聊天室中讨论这个问题,因为您有输入错误。请把“费加罗”改成“费加罗”。我试图编辑,但没有得到提交,因为更改少于6个字符。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能会无效。@eirikir:这不是文档页面;这是您更改设置的实际位置,提供的信息几乎就是您真正需要的全部。因此,将其视为链接唯一的答案是严重错误的。