Home how to whitelabel my heroku app on sendgrid?
Reply: 1

how to whitelabel my heroku app on sendgrid?

Owen
1#
Owen Published in 2018-01-12 18:48:38Z

First i must say i have searched on here high and low and read all of sendgrids and heroku help pages for how to do this and this is my last resort.

I have done the rails tutorial by michael hartl and can not implement the email sign up confirmation. the final step is to whitelabel my sendgrid account.

sendgrid gives some information that I must add to my heroku app but i am lost at this point as i dont know where to enter it and have no idea what exactly i am doing. i am simply following this stage blindly.

the instructions it gives me are

DNS Record information for sending your email with your whitelabel. Copy the following DNS Records into your hosting provider. If you have questions please refer to our documentation.

then it gives me CNAME records with HOST and DATA. I am lost as to where i should enter this information on heroku. I am sorry that this question seems vague but i have never been so lost in asking a question on here so please let me know if there is any further information i can provide to clarify my question.

how to i whitelabel my heroku app on sendgrid?

Rockwell Rice
2#
Rockwell Rice Reply to 2018-01-13 15:24:32Z

this is my setup, I use it for all my apps and works with Heroku + SendGrid.

First, the obvious, make sure you add the sendgrid gem to your gemfile and run bundle install

Gemfile

# Using SendGrid for Emails
gem 'sendgrid'

Then you need a way to access your username and password from sendgrid, I use a .env file so I need the gem for that (and this gem needs to go before the sendgrid gem in the gemfile otherwise it will not work).

Gemfile

# Loads env variables from a .env file
gem 'dotenv-rails'

Then in the root of your app create a .env file and put your username and password in like this.

  • One warning, if you have a public repo make sure to add the .env file to your gitignore file, you do not want to push up those values for anyone to see. Just add the file name to the gitignore file like below.

.gitignore

...other stuff that is ignored...

.env

... maybe more stuff to ignore...

.env

SENDGRID_USERNAME=your_value_here
SENDGRID_PASSWORD=your_value_here

Then, you can use in dev by adding to your development.rb file like this

config/environments/development.rb

Rails.application.routes.default_url_options[:host] = { host:'site_name_here' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
  :from => 'your_email_here',
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain => 'site_name_here',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

And then use in production pretty much the same way, but instead of the .env file, You have to add you username and password as env variables in you Heroku dashboard by going to the app's dashboard, click on settings and then "reveal config vars" and in the dropdown enter the values in with the key value pair you have (SENDGRID_USERNAME and SENDGRID_PASSWORD with their respective values).

config/environments/production.rb

Rails.application.routes.default_url_options[:host] = { host:'site_name_here' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
  :from => 'your_email_here',
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain => 'site_name_here',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

This is the setup I use and it works like a charm, your emails will start to go through.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306305 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO