Ruby on rails 3 RubyonRails操作邮件器-未发送确认电子邮件

Ruby on rails 3 RubyonRails操作邮件器-未发送确认电子邮件,ruby-on-rails-3,actionmailer,Ruby On Rails 3,Actionmailer,我正在从事一个RubyonRails项目,主要是由其他人制作的,我对rails的了解非常有限 注册过程是这样的(或者过去是这样,但由于某些原因,现在似乎不是这样): 一个人用姓名、电子邮件、密码注册。(全部由Desive完成) 该用户会收到一封电子邮件,要求他们点击链接,当他们点击链接时,他们就成为注册用户,可以用自己的姓名和密码登录到该应用程序 当他们执行步骤1并单击“注册”时,屏幕上会出现一条消息:“恭喜!检查您的电子邮件并单击链接。” 但是没有发送电子邮件。在我的App/config/en

我正在从事一个RubyonRails项目,主要是由其他人制作的,我对rails的了解非常有限

注册过程是这样的(或者过去是这样,但由于某些原因,现在似乎不是这样):

  • 一个人用姓名、电子邮件、密码注册。(全部由Desive完成)

  • 该用户会收到一封电子邮件,要求他们点击链接,当他们点击链接时,他们就成为注册用户,可以用自己的姓名和密码登录到该应用程序

  • 当他们执行步骤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),所以我知道这个文件中发生了一些事情。正如我所说,它以前是有效的,我很确定这些是我唯一改变的。还有什么我应该做的吗?

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

    config.action_mailer.perform_deliveries = true
    
    如果没有上述内容,你的应用程序将不会真正发送电子邮件,而只是在你的服务器日志中显示它的内容。。。检查命令行输出(rails服务器正在运行的地方)


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

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

    config.action_mailer.perform_deliveries = true
    
    如果没有上述内容,你的应用程序将不会真正发送电子邮件,而只是在你的服务器日志中显示它的内容。。。检查命令行输出(rails服务器正在运行的地方)


    注意:默认情况下,此设置在生产中启用,因此无需在生产中指定此设置。首先,感谢您的帮助和指导

    @彼得·克利费尔——事实上,你是对的。我只是在刷新我的应用程序,因此没有以下错误消息:

     config.action_mailer.raise_delivery_errors = false
    
    我必须重新启动webrick,它才能生效。完成后,我得到了一个错误:

    Net::SMTPAuthenticationError in Devise::RegistrationsController#create
    
    username and password don't match
    
    正如我所说,我从其他人那里继承了这个项目——问卷调查。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
      }
    

    现在一切都正常运转了(至少目前如此!)

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

    @彼得·克利费尔——事实上,你是对的。我只是在刷新我的应用程序,因此没有以下错误消息:

     config.action_mailer.raise_delivery_errors = false
    
    我必须重新启动webrick,它才能生效。完成后,我得到了一个错误:

    Net::SMTPAuthenticationError in Devise::RegistrationsController#create
    
    username and password don't match
    
    正如我所说,我从其他人那里继承了这个项目——问卷调查。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
      }
    

    现在一切都正常了(至少目前是这样!)

    当您将
    config.action\u mailer.raise\u delivery\u errors
    设置为
    true
    时,会出现什么错误。还是老样子,“一条带有确认链接的消息已经发送到你的电子邮件地址。请打开链接以激活您的帐户。'删除您的密码!您还可以提供当您尝试发送电子邮件时给出的内容的控制台输出。此外,您还更改了`config.mailer\u sender=”changeme@example.com“`它位于
    config/initializers/designe.rb
    当您将
    config.action\u mailer.raise\u delivery\u errors
    设置为
    true
    时,我根本没有收到任何错误。还是老样子,“一条带有确认链接的消息已经发送到你的电子邮件地址。请打开链接以激活您的帐户。'删除您的密码!您还可以提供当您尝试发送电子邮件时给出的内容的控制台输出。此外,您还更改了`config.mailer\u sender=”changeme@example.com“`位于
    config/initializers/develope.rb中