每当我重置密码或尝试收到确认电子邮件时,我都会看到这种错误页面:
Net::SMTPAuthenticationError in Devise::PasswordsController#create
看起来电子邮件正在我的Rails服务器日志中发送,但是在它的底部你可以看到我得到某种500错误。
这只发生在我从开发中发送电子邮件身份验证时(我在下面包含了我的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)
development.rb:
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
答案 0 :(得分:9)
根据与OP的聊天会话,GMAIL_USERNAME
和GMAIL_PASSWORD
未从.env
获取,导致此错误。
对user_name
中的password
和development.rb
进行硬编码非常有效。
我强烈建议您使用figaro
gem,这是安全配置Rails应用程序的绝佳方法。
另外,请阅读 Rails Environment Variables 上 Daniel Kehoe和Taylor Mock 的优秀文章。您还可以了解如何在您的应用程序中使用figaro gem。
答案 1 :(得分:2)
您可以更改Gmail的安全性并激活Google's settings here中不太安全的应用的授权。
答案 2 :(得分:0)
您关注this, or something like it,看起来您的配置正常。
因此,您的用户名/密码错误,或者您在进行这些配置更改后没有重新启动服务器?那条错误信息没有更多内容吗?
答案 3 :(得分:0)
对于发现此帖并且上述任何一个都没有工作的人来说,在导航初始化过程中很早就加载了邮件设置所在的development.rb。
我的修复:
我在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