- Read Tutorial
- Watch Guide Video
In this video, we are going to complete email configuration. I hope you verified the domain. Now, you can see a small green check mark next to DKIM Record. If you verified through email, you'll find the green check near it. This means, we can send email from any account that ends with the domain name we added.
Now, go to application_mailer.rb
and update the email address there. Next, go to devise.rb
and update the domain name there as well.
That's done and we're going to setup our configuration file now, as this is what "SparkPost" is going to check.
It's always a good idea to open the documentation for "SparkPost" to get an idea of what you need to put in your configuration file. I'm going to copy this code from one of my past projects and paste it in a file called setup_mail.rb
. Put it inside the config/initializers
folder.
This is how the file should look:
# config/initializers/setup_mail.rb ActionMailer::Base.smtp_settings = { :port => ENV['SPARKPOST_SMTP_PORT'], :address => ENV['SPARKPOST_SMTP_HOST'], :user_name => ENV['SPARKPOST_SMTP_USERNAME'], :password => ENV['SPARKPOST_SMTP_PASSWORD'], :authentication => :login, :enable_starttls_auto => true } ActionMailer::Base.delivery_method = :smtp
Can you see the ENV
variables? Obviously, you'll have to put them in your .env
file. You can find values for these variables from your dashboard. Once you're done, push these files to heroku.
Restart heroku and run heroku run rake notification:manager_email
This throws an error.
This error has something to do with our configuration. I think we have to configure our host name n heroku.
Open production.rb
and include this:
# config/environments/production.rb config.action_mailer.default_url_options = { :host => 'wlp-overtime.herokuapp.com' }
Now, upload this file, restart heroku and run the rake task again. It works! I got the email.
One thing we need to change is the display name. I think we need a space between the first and last name. Open email.text.erb
, and change it to @manager.first_name + " " + @manager.last_name
.
Upload the change to heroku.