ruby on rails action mailer - 确认电子邮件未发送

时间:2013-06-01 00:10:54

标签: ruby-on-rails-3 actionmailer

我正在开发一个主要由其他人制作的ruby on rails项目,我的导轨知识一般。

注册过程就像这样(或者由于某种原因,现在似乎不习惯):

  1. 一个人注册姓名,电子邮件,密码。 (全部用Devise完成)

  2. 向该人发送电子邮件,要求他们点击链接,当他们这样做时,他们就是注册用户,可以使用他们的姓名和密码登录该应用程序。

    < / LI>

    当他们执行第1步并点击“注册”时,屏幕上会显示一条消息,'恭喜!查看您的电子邮件,然后点击链接。'

    但是没有发送电子邮件。在我的App / config / environments / development.rb中,我有:

    QuestionnaireSite::Application.configure do
      # Settings specified here will take precedence over those in config/application.rb
    
      # In the development environment your application's code is reloaded on
      # every request. This slows down response time but is perfect for development
      # since you don't have to restart the web server when you make code changes.
      config.cache_classes = false
    
      # Log error messages when you accidentally call methods on nil.
      config.whiny_nils = true
    
      # Show full error reports and disable caching
      config.consider_all_requests_local       = true
      config.action_controller.perform_caching = false
    
      # Don't care if the mailer can't send
      config.action_mailer.raise_delivery_errors = false
      config.action_mailer.default_url_options = { :host => 'localhost:3000' }
       config.action_mailer.delivery_method = :smtp
      # config.action_mailer.delivery_method = :letter_opener
      config.action_mailer.smtp_settings = {
          :address              => 'smtp.gmail.com',
          :port                 => 587,
          :domain               => 'gmail.com',
          :user_name            => 'questionnaire.dev@gmail.com',
          :password             => 'qwerty_123',
          :authentication       => 'plain',
          :enable_starttls_auto => true
      }
    
      # Print deprecation notices to the Rails logger
      config.active_support.deprecation = :log
    
      # Only use best-standards-support built into browsers
      config.action_dispatch.best_standards_support = :builtin
    
      # Raise exception on mass assignment protection for Active Record models
      config.active_record.mass_assignment_sanitizer = :strict
    
      # Log the query plan for queries taking more than this (works
      # with SQLite, MySQL, and PostgreSQL)
      config.active_record.auto_explain_threshold_in_seconds = 0.5
    
      # Do not compress assets
      config.assets.compress = false
    
      # Expands the lines which load the assets
      config.assets.debug = true
    
      config.cache_store = :mem_cache_store
    
    end
    

    当我注释掉这一行:

    config.action_mailer.delivery_method = :smtp
    

    并取消注释:

      # config.action_mailer.delivery_method = :letter_opener
    

    一切都按计划进行(letter_opener是一个自动化注册过程的gem)所以我知道这个文件中有一些东西在进行。正如我所说的那样,它之前有效,而且我很确定这些是我改变的唯一线路。还有其他我应该做的事吗?

2 个答案:

答案 0 :(得分:2)

您的development.rb文件以及所有其他内容中需要以下内容:

config.action_mailer.perform_deliveries = true

如果没有上述内容,您的应用程序将不会实际发送电子邮件,而只是在服务器日志中显示其内容...检查命令行输出(rails服务器正在运行的位置)

注意:此设置默认在生产中启用,因此无需在那里指定

答案 1 :(得分:1)

首先,谢谢大家的帮助和指导。

@Peter Klipfel - 事实上,你是对的。我只是刷新我的应用程序,因此没有错误消息:

 config.action_mailer.raise_delivery_errors = false

我必须重新启动webrick才能生效。完成后我得到了错误:

Net::SMTPAuthenticationError in Devise::RegistrationsController#create

username and password don't match

正如我所说,我从其他人那里继承了这个项目 - questionnaire.dev@gmail可能不再存在了。我将代码的这一部分改为:

config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default :charset => "utf-8"

   config.action_mailer.delivery_method = :smtp
  # config.action_mailer.delivery_method = :letter_opener
  config.action_mailer.smtp_settings = {
      :address              => 'smtp.gmail.com',
      :port                 => 587,
      # in previous Stackoverflow I read :domain part wasn't needed, so leave it out
      # :domain               => 'gmail.com',
      :user_name            => 'my_gmail_address@gmail.com',
      :password             => 'my_gmail_password',
      :authentication       => 'plain',
      :enable_starttls_auto => true
  }

现在一切正常(目前无论如何!)