如何通过devise发送确认电子邮件? [英] How to send confirmation emails with devise?
本文介绍了如何通过devise发送确认电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的用户模型:
class用户<应用记录#包括默认的devise模块.其他可用的是:#:timeoutable,:trackable和:omniauthable设计:database_authenticatable,:registerable,:recoverable,:rememberable,:validatable结尾
我应该如何配置devise以在用户注册时发送确认电子邮件?
解决方案
对于生产环境,您需要配置第三方电子邮件发送服务,例如sendgrid.示例:
- 在heroku.com上注册
- 将您的本地应用程序回购推送到github.com
-
heroku create
-
heroku重命名您的应用名称
-
git push heroku master
-
heroku运行rake db:migrate
-
heroku插件:创建sendgrid:starter
environment.rb:
ActionMailer :: Base.smtp_settings = {:address =>"smtp.sendgrid.net",:port =>'587',:authentication =>:清楚的,:user_name =>ENV ['SENDGRID_USERNAME'],:password =>ENV ['SENDGRID_PASSWORD'],:domain =>"heroku.com",:enable_starttls_auto =>真的}
production.rb:
config.action_mailer.default_url_options = {:host =>'your-app-name.herokuapp.com',:protocol =>'https'}config.action_mailer.perform_deliveries = trueconfig.action_mailer.delivery_method =:smtp
这样,您将能够发送/接收生产中的所有设计电子邮件
详细信息: https://devcenter.heroku.com/articles/sendgrid >
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?
解决方案
For production, you need to configure a third-party email sending service, like sendgrid. Example:
- register on heroku.com
- push the your local app repo to 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
That way you will be able to send/receive all devise emails in production
Details: https://devcenter.heroku.com/articles/sendgrid
这篇关于如何通过devise发送确认电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文