How to send confirmation emails with devise?

守給你的承諾、 提交于 2020-07-09 19:39:29

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/61928842/how-to-send-confirmation-emails-with-devise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!