Question

I've been building an app locally and all the mailers used the URL 0.0.0.0:3000 which is what I wanted...

Now I just pushed to heroku, and the URLs didn't update to the product mailer URL. Did I set this up correctly?

/config/environments/production.rb

    config.action_mailer.default_url_options = { :host => 'mynewapp.heroku.com' }

/config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address              => "smtp.sendgrid.net",
  :port                 => "25",
  :authentication       => "plain",
  :domain               => "xxxxxxx.com",
  :user_name            => "xxxx@xxxxxx.com",
  :password             => "xxxxxxxxxxxxx"
}

# The to field is then changed so that the email is sent to
ActionMailer::Base.default_url_options[:host] = "0.0.0.0:3000"
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?

yet all the URLs are still 0.0.0.0:3000 is there some setting I need to set when I push to heroku to specific that rails is in production mode? Or did I mess something up above?

Thanks

Was it helpful?

Solution

Put this line:

ActionMailer::Base.default_url_options[:host] = "0.0.0.0:3000"

in config/environments/development.rb, and also in config/environments/production.rb, but modify it in the latter to be the appropriate URL.

By putting it in an initializer you're setting it up for all environments, which is incorrect.

OTHER TIPS

Add this line to your Gemfile :

gem "action_mailer_auto_url_options"

and URLs will be mapped correctly automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top