Asked  7 Days ago    Answers:  5   Viewed   9 times

I suspect I'm missing something basic here, but been wrestling with this one for a while with no luck.

Rails 4.2.5
Ruby 2.2.3p173

Emails are sending fine on localhost using Amazon SES (I followed this stellar guide) but not on a Heroku production environment. I'm receiving the error in the title of the post:

Errno::ECONNREFUSED (Connection refused - connect(2) for nil port 587)

I suspect the core of the problem is the nil in there, but I haven't been able to figure out where it's coming from. No one else seems to have that problem and even debug level logs don't give me anything more to work with.

I've read dozens of posts like this. But my configurations match all spec as far as I can tell.

Any help/recommendations would be much appreciated.

development.rb

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

  # Configure mailer
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"

    config.action_mailer.smtp_settings = {
      :address => ENV['SES_ADDRESS'],
      :port => 587,
      :enable_starttls_auto => true,
      :user_name => ENV['SES_ACCESS_KEY_ID'],
      :password => ENV['SES_SECRET'],
      :authentication => :login
    }

production.rb

 # Devise
  config.action_mailer.default_url_options = { :host => 'myappname.herokuapp.com'}

  # Configure mailer
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"

    config.action_mailer.smtp_settings = {
      :address => ENV['SES_ADDRESS'],
      :port => 587,
      :enable_starttls_auto => true,
      :user_name => ENV['SES_ACCESS_KEY_ID'],
      :password => ENV['SES_SECRET'],
      :authentication => :login
    }

 Answers

6

Set your environment variables, make sure your SES endpoint is in production mode and you should be good.

Saturday, May 14, 2022
 
2

(Note that the following workaround should only be used if you must use Git sources for dependencies. It is recommended not to install dependencies from external Git repositories if it can be avoided. See below for details on why that is.)

When using Git backed libraries in a Gemfile with Passenger, you must disable shared gems in an installation (in addition to installing Git in the hook you listed above). You can do this by setting the BUNDLE_DISABLE_SHARED_GEMS Bundler environment variable in your existing .ebextensions/ruby.config file like so:

option_settings:
  - option_name: BUNDLE_DISABLE_SHARED_GEMS
    value: "1"
  - option_name: BUNDLE_PATH
    value: "vendor/bundle"

packages:
  yum:
    git: []

Disabling shared gems will force all dependencies to be vendored into your application in vendor/bundle as specified by the BUNDLE_PATH variable.

Note that, whenever possible, you should avoid installing public libraries from Git sources with your application. Using Git for library locations introduces another point of failure for a deployment install, since the Git repository may be temporarily unavailable or even permanently moved. Also keep in mind that forcing vendored installs in a deployment will cause your Elastic Beanstalk deployments to be much slower on subsequent deploys of an app with the same dependencies. This is because the libraries will be re-installed at each deploy instead of taking advantage of the system-wide installation that Elastic Beanstalk has Bundler perform by default.

In short, if there is an official RubyGem release of the library in question, you should use that version instead; and if not, you should suggest to the library author that an official RubyGem release be made available.

FYI a similar question about this Git problem with regular Passenger/Rails deployments was previously asked: Rails 3: Passenger can't find git gems installed by bundler

Monday, June 28, 2021
 
5

An easy way would be to use a rack plugin, something like this:

class RackAssetFilter
   def initialize app
      @app = app
   end

   def call env
      @status, @headers, @body = @app.call env
      if env['PATH_INFO'].starts_with?( "/assets/" )
         @headers['X-Header-1'] = 'value'
         # ... 
      end
      return [@status, @headers, @body]
   end
end

To enable it, in application.rb:

config.middleware.insert_before( ActionDispatch::Static, RackAssetFilter )

Keep in mind you need to declare or load the RackAssetFilter via require before you insert it into the middleware stack in application.rb

Friday, August 13, 2021
 
viper
 
5

Try this

require 'open-uri'
require 'csv'

def import(file)
  CSV.new(open(file), :headers => :true).each do |row|  #First open the file using open
      row_hash = row.to_hash.values
      data = row_hash[0].split("t")
      .
      .
      .
end

For more info you can refer this link

Thursday, November 18, 2021
 
2

Heroku actually sets a URL variable in the environment by default

app_name = ENV['URL'].split(".").first

Referenced here: http://devcenter.heroku.com/articles/config-vars and http://ididitmyway.heroku.com/past/2010/11/9/sinatra_settings_and_configuration/

update: actually the URL variable might not be there by default, but you could always add an environment variable "app name" a priori, unless you were trying to avoid that approach all together.

update 2: indeed, the other, obvious but limiting approach, would be to grab the domain off the request variable, but this limits you to your controller. http://guides.rubyonrails.org/action_controller_overview.html#the-request-object

Friday, December 17, 2021
 
comte
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share