Missing host to link to Rails heroku production - ruby-on-rails

I have an app that I am trying to put onto production. When the user signs up they have an activation email that should be sent to their email accounts but I am getting stopped with this error:
ActionView::Template::Error(Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true)
The problem with this error is that I have everything set up correctly in my files. For example my production.rb file inside my environments folder looks like this:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'secret-everglades-54128.heroku.com'}
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
My enviorments.rb file looks like this:
# Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
config.action_mailer.default_url_options = { :host => 'secret-everglades-54128.heroku.com'}
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
This does not make any sense to me whatsoever, if anyone could shed some light on this problem I will be very great full.

The problem was that I had errors still concuring when I ran the command
git push heroku master
The problem was that I had my host set in the actually environment.rb file which wasn't needed so I removed that and once I did that I was able to get everything to work.

Related

Not receiving mail from Heroku Sendgrid addon

So i've look at a few similar posts here on SO, but for some reason my sendgrid config in heroku is not working.
Here's my config / production.rb
config.action_mailer.default_url_options = { :host => 'poliking.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
ActionMailer::Base.smtp_settings = {
:from => 'wesleycreations#gmail.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'poliking.herokuapp.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
Everything worked perfectly fine in development. I tried all the obvious, YES variables are properly set and YES I enabled my gmail to allow mail from less secure apps.
added gem sendgrid gem to my gem file
gemfile.rb
gem 'sendgrid-ruby'
Again, everything working fine in development and I am receiving email to same email address. But this isn't working in production. Any thoughts?
Here's the log:
...MailForm::Notifier#contact: processed outbound mail in 3.3ms...
Delivered mail 5f246d3cbf2d9_42af68b690f1c810d6#dad81cb4-1ce9-440e-b8...
With config.action_mailer.raise_delivery_errors = false, the errors raised during e-mail delivery will be suppressed.
Therefore, change that option to true so that you can diagnose the problem.

rails config mailer default url options not taking effect (development environment)

I'm working on adjusting the url appearing in a mailer created with,
<%= controller_url %>
but when I change the default with the following command
config.action_mailer.default_url_options = { :host => "example.com", :protocol => 'https', :subdomain => "www"}
the url remains unchanged as
http://localhost:8000/controller
What are some possible causes for this not working? I looked pretty thoroughly through my project folder for places where the host or subdomain might be defined, but found nothing.
EDIT:
It seems I needed to restart my server after making the changes.
I don't know how you trying but I can show my files to compare with yours.
So my development file is /config/environments/development.rb
config.consider_all_requests_local = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
and my production file is /config/environments/production.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => "https://example.com" } #=> Or https://www.example.com
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:user_name => ENV['USERNAME'],
:password => ENV['PASSWORD'],
:domain => 'example.com',
:address => 'smtp.example.net',
:port => 321,
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.delivery_method = :smtp
and it's working perfectly.
Remember these:
Development file is working only when a project is a development mode
Production file is working only when a project is a production mode
And make sure you restarted the server after change anything on related to configuration
You can check the logs while sending mail what's happening and for production run follow this command rails server -e production

Net::SMTPFatalError (550 Unauthenticated senders not allowed; tried varoius methods to solve the issue [duplicate]

I have integrated Sendgrid settings on a Rails 4 server. These settings work fine for development environment. But this is giving error on production environment.
Net::SMTPFatalError (550 Cannot receive from specified address <simmi#mydomain.com>: Unauthenticated senders not allowed)
config/initializers/email_setup.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:domain => DOMAIN,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => "plain",
:enable_starttls_auto => true
}
config/initializers/devise.rb
config.mailer_sender = 'simmi#mydomain.com'
config/environments/production.rb
# Default URL
config.action_mailer.default_url_options = { host: 'mysite.mydomain.com' }
DOMAIN = 'mysite.mydomain.com'
According to sendgrid support team, this error comes when username or password are incorrect. I tried logging manually into the smtp server through telnet and it was working.
On my server commandline, I followed these steps:
telnet smtp.sendgrid.net 587
EHLO
AUTH LOGIN
Enter username in Base64
Enter password in Base64
Link to convert text into Base64 - http://www.opinionatedgeek.com/dotnet/tools/base64encode/
The ENV variables were somehow not working on my production environment. As a workaround, I tried adding the username and password directly and it worked.
I have also faced the same problem and fixed it by adding the following:
config/environment.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:domain => DOMAIN,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options = { host: 'mysite.mydomain.com' }
config/application.rb
ActionMailer::Base.delivery_method = :smtp
The letter_opener gem is very useful if you want to test sending emails in development mode.
If you want to overwrite the letter_opener, add the following configuration
config/environments/development.rb
ActionMailer::Base.delivery_method= :letter_opener
And also add the port under ActionMailer::Base.smtp_settings.
You are probably loading your environment variables after you are trying to initialize your mailer. You can do the initialization directly after loading your variables to be sure that they exist.
Set up a config file with your username and password variables:
# config/mailer.yml
production:
SENDGRID_USERNAME: 'username'
SENDGRID_PASSWORD: 'password'
Set up an initializer file:
# config/initializers/mailer.rb
if Rails.env.production?
config_path = File.expand_path(Rails.root.to_s + '/config/mailer.yml')
if File.exists? config_path
ENV.update YAML.load_file(config_path)[Rails.env]
end
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"],
:domain => "yourdomain",
}
end
If your production environment is Heroku:
Login to your Heroku account and select the application. Under "Settings", click the "Reveal Config Vars" button. Enter in your sendgrid key and value pairs, then submit. Run: heroku restart.

Rails 4 action_mailer host

For Rails 4, I am using config.action_mailer.asset_host = "http://localhost:3000" in
config > environments > development.rb
to load assets to my mailer.
Is there a better value than a hardcoded url? I imagine there should be one since I would not use this value in my production.rb. What is the code to find the current host url in rails config?
If you deploy to a known host, you can put it directly in production.rb
But if you really need to read it from the url, than you check this out
http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url
If you're using SendGrid, inside config/environment.rb file specify your ActionMailer settings to point to SendGrid’s servers.
ActionMailer::Base.smtp_settings = {
:user_name => 'your_sendgrid_username',
:password => 'your_sendgrid_password',
:domain => 'yourdomain.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}

Completed 500 Internal Server Error in Rails 4 Devise Signup process

When I go to signup a new user on the site I fill in the form, click submit, and it sits there for a few seconds, then dispays 'We're sorry, but something went wrong.'
The Log is below...
https://gist.github.com/th3cuda/225f1352a7cfeee3f8f8
This is deployed on digitalocean.
production.rb
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
config.action_mailer.default_url_options = { :host => 'MY_HOST' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.MY_DOMAIN.com',
:port => 465,
:domain => 'MY_DOMAIN',
:user_name => 'MY_EMAIL',
:password => 'PASSWORD',
:authentication => 'plain',
:enable_starttls_auto => true
}
end
Since it's taking a while, it could be looking for sendmail (it uses /usr/sbin/sendmail by default) to send the email.
I would make sure that it's in place, that it can be used by the app, and that the config/(Dev, Prod, etc.) allows it to deliver email.
Is any of that helpful? Let me know what you find so I can give a better answer.
Sorry to add another answer, but formatting here is important.
config.action_mailer.default_url_options = { :host => 'MY_HOST' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtpout.secureserver.net',
:port => 80,
:domain => 'www.example.com',
:user_name => 'johndoe#example.com',
:password => 'yourpassword',
:authentication => 'plain'
}
end
Notice I removed the starttls option, and set port to 80. Obviously, replace with your real values. If you're using constants, please avoid using those until this gets resolved.

Resources