ruby-on-rails - 如何使用设计发送确认电子邮件?
问题描述
这是我的用户模型:
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
环境.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
}
生产.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
这样,您将能够发送/接收生产中的所有设计电子邮件
推荐阅读
- flask - 烧瓶简单路由出错
- android - 如何从数据库修改 LiveData 并将其转发到视图
- visual-studio-code - 如何从自定义语言中为某些标记着色?
- python - PySpark vs sklearn TFIDF
- java - com/migcomponents/migbase64/Base64 的 java.lang.NoClassDefFoundError
- c++ - Sqlite3 和 pthread,双重释放或损坏(出)
- python - 使用 python 的 Cx_oracle 数组
- safari - Safari 显示 Base64 编码的 png 但不显示 svg
- .net - 如何将一个netstandard2.0项目的所有依赖打包到一个包中?
- docker - Docker OCI 运行时创建失败