ruby-on-rails - Rails Devise 发送邮件

标签 ruby-on-rails email devise send

我是通过 Rails 发送邮件的新手。我已经在我的项目中实现了设计,现在我想发送一封欢迎电子邮件和/或一封密码重置电子邮件。我需要在 Devise View 中进行哪些更改? 没有显示任何错误,但我仍然没有收到任何电子邮件。

我点击了这些链接,最后我的 devise.rb、development.rb 和 production.rb 文件如下:

===设计.rb ===

 config.mailer_sender = "xxx@gmail.com"

===development.rb==

  config.action_mailer.raise_delivery_errors = false

  config.action_dispatch.best_standards_support = :builtin

  config.active_support.deprecation = :notify
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = false
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.default :charset => "utf-8"


  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.active_support.deprecation = :log

 config.action_mailer.smtp_settings ={
 :enable_starttls_auto => true,
 :address            => 'smtp.gmail.com',
 :port               => 587,
 :tls                => true,
 :domain             => 'gmail.com',
 :authentication     => :plain,
 :user_name          => 'xxx@gmail.com',
 :password           => 'xxxxxx' 
 }

 =====production.rb===
 config.action_mailer.default_url_options = { :host => 'gmail.com' }

  config.active_support.deprecation = :notify
   config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors =false 
config.action_mailer.default :charset => "utf-8"

  config.action_mailer.smtp_settings = {
  :enable_starttls_auto => true,
  :address            => 'smtp.gmail.com',
  :port               => 587,
  :tls                  => true,
  :domain             => 'gmail.com',
  :authentication     => :plain,
  :user_name          => 'xxx@gmail.com',
  :password           => 'xxxxxx' 
 }

最佳答案

尝试像这样设置 raise_delivery_errors = true:

config.action_mailer.perform_deliveries = true # Set it to false to disable the email in dev mode
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "localhost:3000" }


ActionMailer::Base.smtp_settings = {
                    :address        => "smtp.gmail.com",
                    :port           => 587,
                    :authentication => :plain,
                    :user_name      => "user@gmail.com",
                    :password       => "password"
}

关于ruby-on-rails - Rails Devise 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6993245/

相关文章:

ruby-on-rails - rails 未定义方法 `attr_accessible'

ruby-on-rails - 如何为 Active Admin 命名空间设计两种身份验证模型/路由

ruby-on-rails - 如何在 Rails 应用程序中为 Heroku 上的生产环境设置邮件程序

ruby-on-rails - 在 CSS 中访问 Rails Controller 实例变量

ruby-on-rails - Ruby on Rails 在 jsonb(哈希)中验证日期

php - 使用 Postfix 在 Mountain Lion 上发送电子邮件时的配置问题

PHP 表单消息

mysql - ActiveRecord Many_to_many 具有自定义表和列名称

mysql - Rails 4.1、Ruby 2.1、Devise,为什么我的 .where() 中有多个条件的 'syntax error, unexpected tConstant'?

azure - 使用 Azure DNS 转发电子邮件