首页 > 解决方案 > 如何使用设计发送确认电子邮件?

问题描述

这是我的用户模型:

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

我应该如何配置设计以在用户注册时发送确认电子邮件?

标签: ruby-on-railsrubydevise

解决方案


对于生产,您需要配置第三方电子邮件发送服务,例如 sendgrid。例子:

  1. 在 heroku.com 上注册
  2. 将本地应用程序仓库推送到 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

环境.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

这样,您将能够发送/接收生产中的所有设计电子邮件

详情:https ://devcenter.heroku.com/articles/sendgrid


推荐阅读