Question

I've successfully set up Devise Confirmable with Facebook authentication, and everything works perfectly in development mode. When I push to heroku and run in production mode, the app send an email but the link routes me to:

http://localhost:3000/users/confirmation?confirmation_token=E2jH_ehmHwqy2zyvJGcs

If I replace localhost:3000 with my app name everything works.

In my config/environments/production.rb file I have the following code:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true 

config.action_mailer.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "gmail.com",
  :user_name => ENV["GMAIL_USERNAME"],
  :password => ENV["GMAIL_PASSWORD"],
  :authentication => :plain,
  :enable_starttls_auto => true 
}
config.action_mailer.default_url_options = { :host => 'http://myapp.herokuapp.com' }

And in my development I have:

config.action_mailer.raise_delivery_errors = true

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true 
config.action_mailer.default_url_options = { :host => 'http://localhost:3000' }
config.action_mailer.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "gmail.com",
  :user_name => ENV["GMAIL_USERNAME"],
  :password => ENV["GMAIL_PASSWORD"],
  :authentication => :plain,
  :enable_starttls_auto => true 
}

Any thoughts on what to do? I couldn't find a straight answer anywhere.

I'm using rails 4 & Devise 3.2.4

Was it helpful?

Solution 2

The host value is being over written somewhere in your application. Good place to start with is your initializers directory. Like mentioned elsewhere, check setup_mail.rb under initializers.

Goto Rails console and check the output of:

ActionMailer::Base.default_url_options[:host]

OTHER TIPS

Try this.

config.action_mailer.default_url_options = { host => 'your.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "gmail.com",
  Authentication: "plain",
  enable_starttls_auto: true,
  user_name: your_username,
  password: your_password
}
config.action_mailer.perform_deliveries = true

In production.rb add default_url_options line before the smtp settings and also the host should not contain http://, only write the domain, i.e., myapp.herokuapp.com

config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com' }
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => ENV["GMAIL_USERNAME"],
:password => ENV["GMAIL_PASSWORD"],
:authentication => :plain,
:enable_starttls_auto => true 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top