0
votes

So I'm trying to setup email confirmations for this app, and I've pretty much got it down so far. It's working perfectly in development (using sendgrid), but not in production. It just errors out in production. I've set the config environment (via account I have with sendgrid API integration) I've followed a number of tutorials using both the SMTP method and the WebAPI whatnot. None of it is working. I tried doing a test message with the bundle exec on an rb file, that worked perfectly. The confirmation codes are fine, the emails are going out on development (local environment), but I glitch out on production confirmation emails and only when being sent. The page itself will let me know if there is an error with the email, or if an email is already being used, but it errors out only when sending the email. This tells me that the email code is good, there's just something wrong with my API integration. Here's the code:

./Environments/production.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'bryan-saas-app.herokuapp.com', :protocol => 'https' }

./Initializers/devise.rb:

config.mailer_sender = 'info@mysyte.com'

./Config/environments.rb:

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

}

./sendgrid.env:

export SENDGRID_API_KEY='full api key'
export SENDGRID_USERNAME='apikey'
export SENDGRID_PASSWORD='full api key'

Am I missing something? For what it's worth, I can't access my sendgrid account from the heroku app/config.add-ons area of the dashboard. It errors out there too, so I made a new sendgrid account (personal, non-heroku link) and used an API code from there. Not sure if this would break something.

1

1 Answers

0
votes

Sendgrid has nothing to do with your development environment.

Console:

heroku addons:create sendgrid:starter

application_mailer.rb:

  #replace corsego with your app name
  default from: 'support@corsego.herokuapp.com'

production.rb:

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 
}

environment.rb:

      #replace corsego with your app name
      config.action_mailer.default_url_options = { :host => 'corsego.herokuapp.com', :protocol => 'https' }
      config.action_mailer.perform_deliveries = true
      config.action_mailer.delivery_method = :smtp

Documentation: https://devcenter.heroku.com/articles/sendgrid

Push the changes to production and you're done with sendgrid.

Devise confirmable is explalined step by step here https://github.com/heartcombo/devise/wiki/How-To:-Add-:confirmable-to-Users