【问题标题】:Devise with Rails sending mails使用 Rails 设计发送邮件
【发布时间】:2011-10-23 00:21:55
【问题描述】:

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

我按照下面指定的链接,最后我的 devise.rb、development.rb 和 production.rb 文件如下:

 devise.rb 

 config.mailer_sender = "abc@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          => 'abc@gmail.com',
 :password           => '123456' 
 }

 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          => 'abc@gmail.com',
  :password           => '123456' 
 }

【问题讨论】:

  • 您只在开发中进行测试吗?因为您在那里将perform_deliveries 设置为false
  • @Andrei S:嘿,谢谢!这解决了我的问题! :-)
  • 嘿 thnx @Andrei 也解决了我的问题 :)
  • 我认为这不是问题,这就是为什么我将我的答案添加为评论;我会把它作为答案,这样你就可以关闭它。很高兴为您提供帮助

标签: ruby-on-rails-3 email devise


【解决方案1】:

development 环境中尝试使用rails 发送电子邮件时,您会看到development 的配置文件中有一行config.action_mailer.perform_deliveries = false 指定是否实际发送邮件。

当您创建一个新的 Rails 项目时,该参数会自动设置为 false,如果您想在开发模式下实际发送电子邮件,则必须(除其他外)将该参数设置为 true

【讨论】:

    猜你喜欢
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    相关资源
    最近更新 更多