Search code examples
ruby-on-railsrubydevise

How to send confirmation emails with devise?


Here is my user model:

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  #  :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable
end

How should I configure devise to send confirmation emails when the user signs up?


Solution

  • For production, you need to configure a third-party email sending service, like sendgrid. Example:

    1. register on heroku.com
    2. push the your local app repo to github.com
    3. heroku create
    4. heroku rename your-app-name
    5. git push heroku master
    6. heroku run rake db:migrate
    7. heroku addons:create sendgrid:starter

    environment.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 
    }
    

    production.rb:

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

    That way you will be able to send/receive all devise emails in production

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