[ACCEPTED]-Heroku/devise - Missing host to link to! Please provide :host parameter or set default_url_options[:host]-actionmailer
You need to add this to your environment.rb
config.action_mailer.default_url_options = { :host => 'localhost' }
Make sure you 10 change host
to your production url and keep 9 it localhost for development. This is for 8 the mailer, it needs a default email to 7 send out notices such as confirmations etc...
You 6 should check the logs on the heroku server 5 heroku logs
run that from the console and it will tell 4 you the exact error.
When you push to heroku 3 you need to configure the environment.rb
file with the 2 heroku subdomain:
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
Depending upon version, this 1 should go in production.rb
, not environment.rb
.
Ok,
First you have to install the sendgrid 4 gem with this command line:
heroku addons:add sendgrid:free
Then you just 3 have to configure your env/dev.rb and env/prod.rb 2 like this:
env/dev.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
env/prod.rb
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
Push on git 1 and heroku. It should work..
Codeglot's anwser above does the job, but 7 we wanted something a bit more flexible, so 6 we did this:
On Heroku, we run multiple Production 5 environments for staging and testing, so 4 we need a flexible solution for the production.rb 3 environment file.
In production.rb
config.action_mailer.default_url_options = { :host => ENV['MAILER_URL'] }
Then set 2 the MAILER_URL environment variable for 1 your app like so
heroku config:set MAILER_URL=my-awesome-app.herokuapp.com --app my-awesome-app
If you're running on Cedar:
run
heroku addons:add sendgrid:free
from your console.Add the following 1 lines to
config/environments/production.rb
in your app.
.
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com'
}
ActionMailer::Base.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'YOUR-DOMAIN-HERE.COM' }
I had to do a number of things to get it 3 to work in the production environment:
Inside of 2 my production.rb
file (/config/environments/production.rb) I 1 added the following:
Rails.application.routes.default_url_options[:host] = 'myappsname.herokuapp.com'
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
This is with Rails 4 and Devise 3
The working one after so many research,
Don't 4 forget to add default from: mail address in your ApplicationMailer (application_mailer.rb) as,
class ApplicationMailer < ActionMailer::Base default from: 'yourmail@gmail.com' layout 'mailer' end
Add 3 the below configuration in your production.rb.
config.action_mailer.default_url_options = { :host => 'yourapp.herokuapp.com' } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'heroku.com', user_name: 'yourmail@gmail.com', password: 'yourgmailpassword', authentication: 'login', enable_starttls_auto: true }
Enable 2 IMAP from your Gmail settings in Forwarding IMAP/POP tab.
Allow less secure apps: ON from 1 https://myaccount.google.com/lesssecureapps
You're now good to go. :)
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.