Sendgrid heroku error

I am using sendgrid in my rails application to send email confirmation links to users. Here is my setup:

  • In my environments/production.rb file
Rails.application.configure do
  ActionMailer::Base.smtp_settings = {
    :address => 'smtp.sendgrid.net',
    :port => '587',
    :authentication => :plain,
    :user_name => Rails.application.credentials.dig(:sendgrid, :user_name),
    :password => Rails.application.credentials.dig(:sendgrid, :password),
    :domain => 'heroku.com',
    :enable_starttls_auto => true
  }
  
  config.action_mailer.default_url_options = { :host => 'e-learning-bld.herokuapp.com', :protocol => 'https'}
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp

I did the same configurations in environments/development.rb file except with the following change:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

The functionality works in my development environment but when I attempt to sign up a user on heroku I get an error with the log below:

2021-05-04T20:25:34.747909+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
2021-05-04T20:25:34.747910+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
2021-05-04T20:25:34.747910+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
2021-05-04T20:25:34.747911+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
2021-05-04T20:25:34.747911+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
2021-05-04T20:25:34.747912+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activerecord (6.1.3.1) lib/active_record/connection_adapters/abstract/transaction.rb:285:in `commit_transaction'
2021-05-04T20:25:34.747912+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activerecord (6.1.3.1) lib/active_record/connection_adapters/abstract/transaction.rb:340:in `block in within_new_transaction'
2021-05-04T20:25:34.747913+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
2021-05-04T20:25:34.747913+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
2021-05-04T20:25:34.747913+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
2021-05-04T20:25:34.747914+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
2021-05-04T20:25:34.747914+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
2021-05-04T20:25:34.747915+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activerecord (6.1.3.1) lib/active_record/connection_adapters/abstract/transaction.rb:308:in `within_new_transaction'
2021-05-04T20:25:34.747915+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activerecord (6.1.3.1) lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
2021-05-04T20:25:34.747916+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activerecord (6.1.3.1) lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
2021-05-04T20:25:34.747916+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activerecord (6.1.3.1) lib/active_record/transactions.rb:298:in `save'
2021-05-04T20:25:34.747916+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activerecord (6.1.3.1) lib/active_record/suppressor.rb:44:in `save'
2021-05-04T20:25:34.747917+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] devise (4.7.3) app/controllers/devise/registrations_controller.rb:19:in `create'
2021-05-04T20:25:34.747917+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
2021-05-04T20:25:34.747917+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/abstract_controller/base.rb:228:in `process_action'
2021-05-04T20:25:34.747918+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
2021-05-04T20:25:34.747919+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
2021-05-04T20:25:34.747919+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/callbacks.rb:117:in `block in run_callbacks'
2021-05-04T20:25:34.747919+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] public_activity (1.6.4) lib/public_activity/utility/store_controller.rb:27:in `store_controller_for_public_activity'
2021-05-04T20:25:34.747920+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/callbacks.rb:126:in `block in run_callbacks'
2021-05-04T20:25:34.747920+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actiontext (6.1.3.1) lib/action_text/rendering.rb:20:in `with_renderer'
2021-05-04T20:25:34.747921+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actiontext (6.1.3.1) lib/action_text/engine.rb:55:in `block (4 levels) in <class:Engine>'
2021-05-04T20:25:34.747921+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/callbacks.rb:126:in `instance_exec'
2021-05-04T20:25:34.747926+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/callbacks.rb:126:in `block in run_callbacks'
2021-05-04T20:25:34.747926+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/callbacks.rb:137:in `run_callbacks'
2021-05-04T20:25:34.747927+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
2021-05-04T20:25:34.747927+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
2021-05-04T20:25:34.747928+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
2021-05-04T20:25:34.747928+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/notifications.rb:203:in `block in instrument'
2021-05-04T20:25:34.747929+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
2021-05-04T20:25:34.747929+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/notifications.rb:203:in `instrument'
2021-05-04T20:25:34.747930+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_controller/metal/instrumentation.rb:33:in `process_action'
2021-05-04T20:25:34.747930+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
2021-05-04T20:25:34.747931+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activerecord (6.1.3.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
2021-05-04T20:25:34.747931+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/abstract_controller/base.rb:165:in `process'
2021-05-04T20:25:34.747931+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionview (6.1.3.1) lib/action_view/rendering.rb:39:in `process'
2021-05-04T20:25:34.747932+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_controller/metal.rb:190:in `dispatch'
2021-05-04T20:25:34.747932+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_controller/metal.rb:254:in `dispatch'
2021-05-04T20:25:34.747932+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
2021-05-04T20:25:34.747933+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
2021-05-04T20:25:34.747933+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
2021-05-04T20:25:34.747934+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/routing/mapper.rb:49:in `serve'
2021-05-04T20:25:34.747934+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/journey/router.rb:50:in `block in serve'
2021-05-04T20:25:34.747935+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/journey/router.rb:32:in `each'
2021-05-04T20:25:34.747935+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/journey/router.rb:32:in `serve'
2021-05-04T20:25:34.747935+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/routing/route_set.rb:842:in `call'
2021-05-04T20:25:34.747936+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] exception_notification (4.4.3) lib/exception_notification/rack.rb:49:in `call'
2021-05-04T20:25:34.747936+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
2021-05-04T20:25:34.747937+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] warden (1.2.9) lib/warden/manager.rb:34:in `catch'
2021-05-04T20:25:34.747937+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] warden (1.2.9) lib/warden/manager.rb:34:in `call'
2021-05-04T20:25:34.747938+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
2021-05-04T20:25:34.747938+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/etag.rb:27:in `call'
2021-05-04T20:25:34.747939+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/conditional_get.rb:40:in `call'
2021-05-04T20:25:34.747939+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/head.rb:12:in `call'
2021-05-04T20:25:34.747939+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/http/permissions_policy.rb:22:in `call'
2021-05-04T20:25:34.747940+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
2021-05-04T20:25:34.747940+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
2021-05-04T20:25:34.747941+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
2021-05-04T20:25:34.747941+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/cookies.rb:689:in `call'
2021-05-04T20:25:34.747945+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
2021-05-04T20:25:34.747946+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
2021-05-04T20:25:34.747946+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
2021-05-04T20:25:34.747947+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
2021-05-04T20:25:34.747947+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
2021-05-04T20:25:34.747947+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
2021-05-04T20:25:34.747948+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] railties (6.1.3.1) lib/rails/rack/logger.rb:37:in `call_app'
2021-05-04T20:25:34.747948+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] railties (6.1.3.1) lib/rails/rack/logger.rb:26:in `block in call'
2021-05-04T20:25:34.747949+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:99:in `block in tagged'
2021-05-04T20:25:34.747949+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:37:in `tagged'
2021-05-04T20:25:34.747950+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:99:in `tagged'
2021-05-04T20:25:34.747950+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] railties (6.1.3.1) lib/rails/rack/logger.rb:26:in `call'
2021-05-04T20:25:34.747950+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
2021-05-04T20:25:34.747951+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/request_id.rb:26:in `call'
2021-05-04T20:25:34.747951+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/method_override.rb:24:in `call'
2021-05-04T20:25:34.747951+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/runtime.rb:22:in `call'
2021-05-04T20:25:34.747952+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] activesupport (6.1.3.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
2021-05-04T20:25:34.747952+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
2021-05-04T20:25:34.747952+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/static.rb:24:in `call'
2021-05-04T20:25:34.747953+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
2021-05-04T20:25:34.747953+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] actionpack (6.1.3.1) lib/action_dispatch/middleware/host_authorization.rb:92:in `call'
2021-05-04T20:25:34.747954+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] railties (6.1.3.1) lib/rails/engine.rb:539:in `call'
2021-05-04T20:25:34.747954+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] puma (5.2.2) lib/puma/configuration.rb:248:in `call'
2021-05-04T20:25:34.747954+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] puma (5.2.2) lib/puma/request.rb:76:in `block in handle_request'
2021-05-04T20:25:34.747955+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] puma (5.2.2) lib/puma/thread_pool.rb:337:in `with_force_shutdown'
2021-05-04T20:25:34.747955+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] puma (5.2.2) lib/puma/request.rb:75:in `handle_request'
2021-05-04T20:25:34.747956+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] puma (5.2.2) lib/puma/server.rb:431:in `process_client'
2021-05-04T20:25:34.747956+00:00 app[web.1]: [ab62333e-5786-4c67-9291-bf96245eda15] puma (5.2.2) lib/puma/thread_pool.rb:145:in `block in spawn_thread'
2021-05-04T20:25:34.757175+00:00 heroku[router]: at=info method=POST path="/" host=e-learning-bld.herokuapp.com request_id=ab62333e-5786-4c67-9291-bf96245eda15 fwd="93.175.115.96" dyno=web.1 connect=1ms service=1525ms status=500 bytes=1827 protocol=https
2021-05-04T20:25:37.124638+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=e-learning-bld.herokuapp.com request_id=344887f9-753b-4a1e-8d35-e12c01bca23b fwd="93.175.115.96" dyno=web.1 connect=1ms service=3ms status=200 bytes=143 protocol=https
2021-05-04T20:26:10.027903+00:00 heroku[web.1]: Idling
2021-05-04T20:26:10.045250+00:00 heroku[web.1]: State changed from up to down
2021-05-04T20:26:14.913648+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-05-04T20:26:15.008255+00:00 app[web.1]: - Gracefully stopping, waiting for requests to finish
2021-05-04T20:26:15.252933+00:00 app[web.1]: Exiting
2021-05-04T20:26:15.429991+00:00 heroku[web.1]: Process exited with status 143

The problem I can’t figure out what the error is from the log. Any help?

Do you have the SendGrid add-on set up on Heroku? If so, try adding ENV variables on Heroku for SendGrid credentials and use the ENV vars in place of Rails credentials just to be sure. Looks like you have problems authenticating on SendGrid.

Yes I have sendgrid add-ons setup on heroku. I’ll try accessing the sendgrid credentails with environment variables and let you know if it works. Thanks!