ruby-on-railsenvironment-variablesdigital-oceansendgrideconnrefused

SendGrid + Ruby on Rails 6 on DigitalOcean Apps + Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):


I believe this error is about ENV API Key. This works fine on my localhost but on server.

I added my API key to Components / Environment Variables: enter image description here

and my development.rb file. as below:

  config.action_mailer.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    :address        => "smtp.sendgrid.net",
    :port           => "587",
    :authentication => :plain,
    :user_name      => 'apikey',
    :password       => ENV['SENDGRID_API_KEY']
  }

And I still get the error as below

Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):


Solution

  • ARGH! Wasted 2 days on this. All I have to do was adding the Actionmailer settings to

    production.rb

    I had it only in development.rb file before. Duh!!