如何使用devise发送确认邮件?
How to send confirmation emails with devise?
这是我的用户模型:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable
end
我应该如何配置设备以在用户注册时发送确认电子邮件?
对于生产,您需要配置第三方电子邮件发送服务,如 sendgrid。示例:
- 注册 heroku.com
- 将您的本地应用回购推送到 github.com
heroku create
heroku rename your-app-name
git push heroku master
heroku run rake db:migrate
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
这样你就可以send/receive生产中的所有设计电子邮件
这是我的用户模型:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable
end
我应该如何配置设备以在用户注册时发送确认电子邮件?
对于生产,您需要配置第三方电子邮件发送服务,如 sendgrid。示例:
- 注册 heroku.com
- 将您的本地应用回购推送到 github.com
heroku create
heroku rename your-app-name
git push heroku master
heroku run rake db:migrate
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
这样你就可以send/receive生产中的所有设计电子邮件