我之前已经看过这个问题,并提出了不同的问题。我跟着http://railscasts.com/episodes/61-sending-email-revised。它在开发中工作,但我不明白为什么它在生产中不起作用。任何的想法?我正在heroku上部署。
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "mlpinit.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
[编辑]
MLP $
heroku logs
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/persistence.rb:84:in `save'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:241:in `block in save'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:241:in `block (2 levels) in save'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:208:in `transaction'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:145:in `block in deliver!'
2012-09-27T20:59:25+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/net/smtp.rb:526:in `start'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:144:in `deliver!'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:34:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/app/controllers/devise/registrations_controller.rb:15:in `create'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/abstract_controller/base.rb:167:in `process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in `block in instrument'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/abstract_controller/base.rb:121:in `process'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/routing/route_set.rb:66:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal/rescue.rb:29:in `process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/engine.rb:479:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/application.rb:220:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/routing/route_set.rb:30:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:35:in `block in call'
2012-09-27T20:59:25+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
2012-09-27T20:59:25+00:00 app[web.1]:
2012-09-27T20:59:25+00:00 app[web.1]:
2012-09-27T20:59:25+00:00 app[web.1]: cache: [POST /users] invalidate, pass
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `_run__1589555729654806650__call__1942553407593038289__callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/etag.rb:23:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/conditionalget.rb:35:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/head.rb:14:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/rack/logger.rb:26:in `call_app'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/rack/logger.rb:16:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/request_id.rb:22:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/flash.rb:242:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/cookies.rb:338:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/query_cache.rb:64:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/static.rb:53:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:143:in `pass'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:155:in `invalidate'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/
1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:71:in `call!'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/rack/log_tailer.rb:14:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
2012-09-27T20:59:25+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:420:in `_run__4395379426680443846__create__1942553407593038289__callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/callbacks.rb:264:in `block in create_or_update'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/callbacks.rb:264:in `create_or_update'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:190:in `transaction'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:447:in `_run__1974915937284874341__process_action__151418621781748778__callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/abstract_controller/callbacks.rb:17:in `process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in `instrument'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/attribute_methods/dirty.rb:22:in `save'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:414:in `_run__4395379426680443846__save__1942553407593038289__callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/validations.rb:50:in `save'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/abstract_controller/rendering.rb:45:in `process'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:240:in `save'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal/rendering.rb:10:in `process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal.rb:203:in `dispatch'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_controller/metal.rb:246:in `block in action'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/routing/mapper.rb:40:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/routing/route_set.rb:589:in `call'
2012-09-27T20:59:25+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb:34:in `catch'
2012-09-27T21:21:20+00:00 heroku[router]: GET trackit.mlpinit.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=5ms status=200 bytes=0
2012-09-27T21:21:20+00:00 heroku[nginx]: 71.206.13.38 - - [27/Sep/2012:21:21:20 +0000] "GET /favicon.ico HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1" trackit.mlpinit.com
2012-09-27T21:21:20+00:00 app[web.1]: cache: [GET /favicon.ico] miss
[EDIT2]
发现此错误
(Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true)
我添加了config.action_mailer.default_url_options = { :host => 'trackit-mlpinit.herokuapp.com' }
这是我现在得到的错误。
[EDIT3]
Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at
2012-09-27T22:25:45+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/net/smtp.rb:954:in `check_response'
2012-09-27T22:25:45+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/net/smtp.rb:923:in `getok'
2012-09-27T22:25:45+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/net/smtp.rb:838:in `mailfrom'
2012-09-27T22:25:45+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/net/smtp.rb:665:in `send_message'
2012-09-27T22:25:45+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:145:in `block in deliver!'
[EDIT4] 原来我必须将ENV变量导出到heroku。
https://devcenter.heroku.com/articles/config-vars#setting-up-config-vars-for-a-deployed-application
答案 0 :(得分:1)
您尚未设置:host
变量来解析邮件程序模板中的所有link_to
方法。将其设置为您的应用域,一切都会正常。
答案 1 :(得分:1)
在你的config / environments / production.rb中(假设你正在制作中)像这样设置主机:
config.action_mailer.default_url_options = { host: 'mlpinit.com' }