我尝试了以下代码片段,以便在设计时自定义重置密码
class CustomMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views
def reset_password_instructions(record, token, opts={})
@resource = record
mail(:to => "#{@resource.full_name} <#{@resource.email}>", :subject => "Reset password instructions", :tag => 'password-reset', :content_type => "text/html") do |format|
format.html { render "devise/mailer/reset_password_instructions" }
end
end
端
并在 Devise.rb 中定义为
config.mailer = 'CustomMailer'
哪个在本地机器/ dev env上完全正常,但在生产中我收到的错误如下:
ArgumentError (An SMTP From address is required to send a message. Set the message smtp_envelope_from, return_path, sender, or from address.):
vendor/bundle/ruby/2.0.0/gems/mail-2.6.1/lib/mail/check_delivery_params.rb:5:in `check_delivery_params'
vendor/bundle/ruby/2.0.0/gems/mail-2.6.1/lib/mail/network/delivery_methods/smtp.rb:98:in `deliver!'
vendor/bundle/ruby/2.0.0/gems/mail-2.6.1/lib/mail/message.rb:2136:in `do_delivery'
vendor/bundle/ruby/2.0.0/gems/mail-2.6.1/lib/mail/message.rb:232:in `block in deliver'
vendor/bundle/ruby/2.0.0/gems/actionmailer-4.1.6/lib/action_mailer/base.rb:527:in `block in deliver_mail'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/notifications.rb:159:in `block in instrument'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/notifications.rb:159:in `instrument'
vendor/bundle/ruby/2.0.0/gems/actionmailer-4.1.6/lib/action_mailer/base.rb:525:in `deliver_mail'
vendor/bundle/ruby/2.0.0/gems/mail-2.6.1/lib/mail/message.rb:232:in `deliver'
vendor/bundle/ruby/2.0.0/gems/devise-3.3.0/lib/devise/models/authenticatable.rb:173:in `send_devise_notification'
vendor/bundle/ruby/2.0.0/gems/devise-3.3.0/lib/devise/models/recoverable.rb:99:in `send_reset_password_instructions_notification'
vendor/bundle/ruby/2.0.0/gems/devise-3.3.0/lib/devise/models/recoverable.rb:49:in `send_reset_password_instructions'
vendor/bundle/ruby/2.0.0/gems/devise-3.3.0/lib/devise/models/recoverable.rb:116:in `send_reset_password_instructions'
vendor/bundle/ruby/2.0.0/gems/devise-3.3.0/app/controllers/devise/passwords_controller.rb:13:in `create'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/abstract_controller/base.rb:189:in `process_action'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal/rendering.rb:10:in `process_action'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:113:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:113:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:229:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:229:in `block in halting'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:149:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:229:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:229:in `block in halting'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `block in halting'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:86:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:86:in `run_callbacks'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/abstract_controller/callbacks.rb:19:in `process_action'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal/rescue.rb:29:in `process_action'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/notifications.rb:159:in `block in instrument'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/notifications.rb:159:in `instrument'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.6/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/abstract_controller/base.rb:136:in `process'
vendor/bundle/ruby/2.0.0/gems/actionview-4.1.6/lib/action_view/rendering.rb:30:in `process'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal.rb:196:in `dispatch'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_controller/metal.rb:232:in `block in action'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:82:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:50:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/mapper.rb:45:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/journey/router.rb:73:in `block in call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/journey/router.rb:59:in `each'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/journey/router.rb:59:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:678:in `call'
vendor/bundle/ruby/2.0.0/gems/rack-attack-4.2.0/lib/rack/attack.rb:104:in `call'
vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:35:in `call'
vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/flash.rb:254:in `call'
vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/cookies.rb:560:in `call'
vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.6/lib/active_record/query_cache.rb:36:in `call'
vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:82:in `run_callbacks'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:38:in `call_app'
vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:20:in `block in call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:68:in `block in tagged'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:68:in `tagged'
vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:20:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/request_id.rb:21:in `call'
vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/ssl.rb:24:in `call'
vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
vendor/bundle/ruby/2.0.0/gems/puma-2.9.1/lib/puma/configuration.rb:71:in `call'
vendor/bundle/ruby/2.0.0/gems/puma-2.9.1/lib/puma/server.rb:490:in `handle_request'
vendor/bundle/ruby/2.0.0/gems/puma-2.9.1/lib/puma/server.rb:361:in `process_client'
vendor/bundle/ruby/2.0.0/gems/puma-2.9.1/lib/puma/server.rb:254:in `block in run'
vendor/bundle/ruby/2.0.0/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `call'
vendor/bundle/ruby/2.0.0/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `block in spawn_thread'
答案 0 :(得分:0)
您是否在config / environments / production.rb中设置了smtp设置?