1

I'm working on a ruby on rails project made mostly by someone else, and my rails knowledge is so-so.

The registration process works like this (or used to, but doesn't seem to now, for some reason):

  1. A person registers with name, email, password. (All done with Devise)

  2. The person is sent an email, asking them to click on a link, and when they do, they are then a registered user and can log in to the app with their name and password.

When they do step 1 and click 'Sign Up' a message comes up on the screen, 'Congratulations! Check your email and click the link.'

But no email is being sent. In my App/config/environments/development.rb I have:

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

When I comment out the line:

config.action_mailer.delivery_method = :smtp

and uncomment:

  # config.action_mailer.delivery_method = :letter_opener

Everything works as planned (letter_opener is a gem that automates the registration process) so I know there's something going on in this file. As I said, it was working before, and I'm pretty sure those are the only lines I've changed. Is there something else I should be doing?

4

2 回答 2

3

You need the following in your development.rb file as well as all the other stuff:

config.action_mailer.perform_deliveries = true

Without the above, your app won't actually send the email, and instead will simply display it's contents in your server log... Check the command line output (where rails server is running)

Note: this setting is enabled by default in production, so there's no need to specify it there

于 2013-06-01T04:33:48.963 回答
1

First of all, thank you all above for your help and guidance.

@Peter Klipfel - in fact, you were right. I was simply refreshing my app, therefore no error messages with:

 config.action_mailer.raise_delivery_errors = false

I had to restart webrick for it to take effect. When that was done I got the error:

Net::SMTPAuthenticationError in Devise::RegistrationsController#create

username and password don't match

As I said, I inherited this project from someone else - questionnaire.dev@gmail probably doesn't exist any more. I changed that part of the code to:

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
  }

And now everything works as it should (for the moment anyway!)

于 2013-06-01T08:40:24.133 回答