简体   繁体   中英

Devise: Completed 401 Unauthorized

Previously, I had no issues with Devise sending email confirmations to newly registered users in my Rails app.

Recently I changed the password of the mailer and updated the rails app to include the updated password in my application.yml file. Now, whenever I try to register a user and send a confirmation email, the email doesn't ever seem to be sent (I know this because I don't receive the confirmation and it doesn't show up in the "sent" folder of my mailer account). I also get a Completed 401 Unauthorized message in my logs.

Anyone know how to fix this? Complete logs below:

Processing by RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"yqC4atQ1Ma8TCvMWBU+u1uCih5zEaCU1gms5FXwdiH8=", "user"=>{"username"=>"testuser2", "email"=>"testuser@test.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
#<User id: nil, email: "testuser@test.com", encrypted_password: "$2a$10$FwdfSCcBlGSy7xlxwabk1eI1sP/QNnT13Aw3sTnLvsdO...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, failed_attempts: 0, unlock_token: nil, locked_at: nil, authentication_token: nil, created_at: nil, updated_at: nil, username: "testuser2", avatar: nil, notifications_viewed_at: nil, about_me: nil>
(2.1ms)  BEGIN
User Exists (17.5ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'testuser@test.com' LIMIT 1
User Load (5.7ms)  SELECT "users".* FROM "users" WHERE "users"."authentication_token" = 'i2zA7pTvuADyZwtbjLQB' LIMIT 1
User Load (9.7ms)  SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'c458bfc8a3cd8a6d3083e6464872753e7f9670b2828df463a9030186af8f2de7' LIMIT 1
    2014-02-14T20:10:59.099332+00:00 app[web.1]:   SQL (109.1ms)  INSERT INTO "users" ("about_me", "authentication_token", "avatar", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "failed_attempts", "last_sign_in_at", "last_sign_in_ip", "locked_at", "notifications_viewed_at", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "unconfirmed_email", "unlock_token", "updated_at", "username") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24) RETURNING "id"  [["about_me", nil], ["authentication_token", "i2zA7pTvuADyZwtbjLQB"], ["avatar", nil], ["confirmation_sent_at", Fri, 14 Feb 2014 15:10:58 EST -05:00], ["confirmation_token", "c458bfc8a3cd8a6d3083e6464872753e7f9670b2828df463a9030186af8f2de7"], ["confirmed_at", nil], ["created_at", Fri, 14 Feb 2014 15:10:58 EST -05:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", "testuser@test.com"], ["encrypted_password", "$2a$10$FwdfSCcBlGSy7xlxwabk1eI1sP/QNnT13Aw3sTnLvsdOya505O1w6"], ["failed_attempts", 0], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["locked_at", nil], ["notifications_viewed_at", nil], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["sign_in_count", 0], ["unconfirmed_email", nil], ["unlock_token", nil], ["updated_at", Fri, 14 Feb 2014 15:10:58 EST -05:00], ["username", "testuser2"]]
Rendered devise/mailer/confirmation_instructions.html.erb (1.4ms)
    Sent mail to testuser@test.com (672.6ms)
    (5.9ms)  COMMIT
    (8.5ms)  BEGIN
    (15.6ms)  COMMIT
    Completed 401 Unauthorized in 2966.9ms

development.rb

config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { :host => ENV['DEV_HOST_URL'] }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
    :enable_starttls_auto => true,
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "gmail.com",
    :authentication => :login,
    :user_name => ENV["GMAIL_USERNAME"], 
    :password => ENV["GMAIL_PASSWORD"]
  }

Did you reload/restart your server? The yml file will not be reloaded on save or change. These files are only read at startup time of the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM