HOW TO GET DEVISE, FIGARO, HEROKU AND EMAILING TO PLAY TOGETHER NICELY
I recently made the switch over to SparkPost, which is one of Heroku’s newest add-ons (I also work there)! There is a free basic plan that includes up to 10K of emails a month. SparkPost has the highest inbox placement of any provider, and real-time analytics with over 40 different metrics. It's also built by Message Systems, which is the email provider for large scale companies like Facebook, Twitter, and Pinterest, so that made migration an easy choice! The move was straight forward, quick, and easy!
Once you have a card on file, just run
heroku addons:create sparkpost:free
to add SparkPost to your app.
I'm going to write this from the standpoint of where I was last week so here's some background. I, like many other newbies was happily going along completing various Rails Tutorials not aware that my "secret token" was being committed to my public GitHub repo for the world to see. For random tutorials this isn't really a problem, but when it's time to start an actual app you plan to deploy, then this is going to be necessary. The solution... environment variables. There are a ton of ways to go about hiding your apps token (and other confidential info like emails and passwords), but I opted for Figaro.
Configuration is pretty straight forward. Add Figaro to your Gemfile and run
$ bundle install
$ rails generate figaro:install
Figaro's generate command will create an application.yml file for you and automatically add it to your .gitignore!
Now, add the variables you want hidden into config/application.yml.
It will look something like this if you use Gmail:
$ rake figaro:heroku
to add your environment variables to Heroku. If you're like me and want to see proof, you can run
$ heroku config
just to make sure they're there.
Now for the emails. (It's worth mentioning, that I used my gmail account initially). Heroku recommends SendGrid, and I'm glad I went this route. The basic plan is free and comes with 6K emails monthly. You'll need a credit card on file with Heroku, but there are no charges if you remain in that range.
Once you have a card on file, run
heroku addons:add sendgrid:starter
to add SendGrid to your app.
To generate your apps email run
$ heroku config:get SENDGRID_USERNAME,
$ heroku config:get SENDGRID_PASSWORD
to generate your password.
Ok, almost there. Now back to your app's directory. In config/initializers/devise.rb, find
and set that to your SendGrid email environment variable (that was generated for you when running the commands above). It will look like this:
Next, in envrionments/production.rb you'll need to include the following for Devise.
Run through your deploy process and you will be good to go!