【问题标题】:Reset password email is not sent by Devise重设密码电子邮件不是由设计发送的
【发布时间】:2013-04-29 01:39:08
【问题描述】:

Rails 3.2.13、Ruby 1.9.3

我的 Devise 控制器在发送电子邮件时工作正常,但有一个例外:发送重置密码说明电子邮件。

当我点击“忘记密码?”时链接,我收到消息:

You will receive an email with your password reset instructions in a few minutes.

但是,我没有收到电子邮件。以下是日志文件中的相关转储:

Started GET "/password/new.user" for 174.xx.xxx.xx at 2013-04-29 01:28:48 +0000
Processing by Devise::PasswordsController#new as 
  BlogPost Load (0.5ms)  SELECT `blog_posts`.* FROM `blog_posts` 
  Rendered devise/_links.erb (1.0ms)
  Rendered devise/passwords/new.html.erb within layouts/application (23.1ms)
  Rendered layouts/_shim.html.erb (0.0ms)
  Rendered layouts/_header.html.erb (2.5ms)
  Rendered layouts/_promo_bar.html.erb (0.9ms)
  Rendered layouts/_footer.html.erb (2.6ms)
Completed 200 OK in 54ms (Views: 51.2ms | ActiveRecord: 0.5ms)
Started POST "/password" for 174.xx.xxx.xx at 2013-04-29 01:30:19 +0000
Processing by Devise::PasswordsController#create as HTML
  Parameters: {"utf8"=>"✓", "user"=>{"email"=>"emailaddress@outlook.com"}, "commit"=>"Send me reset password instructions"}
  BlogPost Load (137.8ms)  SELECT `blog_posts`.* FROM `blog_posts` 
  User Load (82.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`email` = 'emailaddress@outlook.com' LIMIT 1
  User Load (14.8ms)  SELECT `users`.* FROM `users` WHERE `users`.`reset_password_token` = 'NysDaribCpgNySc5Nmog' LIMIT 1
   (0.2ms)  BEGIN
   (99.0ms)  UPDATE `users` SET `reset_password_token` = 'NysDaribCpgNySc5Nmog', `reset_password_sent_at` = '2013-04-29 01:30:19', `updated_at` = '2013-04-29 01:30:19' WHERE `users`.`id` = 113
   (60.6ms)  COMMIT
  Rendered devise/mailer/reset_password_instructions.html.erb (1.3ms)
  Rendered devise/mailer/reset_password_instructions.text.erb (1.5ms)

Sent mail to emailaddress@outlook.com (133ms)
Date: Mon, 29 Apr 2013 01:30:21 +0000
To: emailaddress@outlook.com
Message-ID: <517dcd2db584b_71bc6778701193@testsite-test.mail>
Subject: testsite Account Reset password instructions
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_517dcd2d93927_71bc677870116dc";
 charset=UTF-8
Content-Transfer-Encoding: 7bit



----==_mimepart_517dcd2d93927_71bc677870116dc
Date: Mon, 29 Apr 2013 01:30:21 +0000
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <517dcd2d9bfb9_71bc677870117a2@testsite-test.mail>

Hello emailaddress@outlook.com!

A Request to change the password for this account has been received. If this is you, and you still want to change the password, you can do so by clicking on the link below.

<a href="http://test.testsitethefuture.com/password/edit?reset_password_token=NysDaribCpgNySc5Nmog">Change my password</a>

If you didn&#x27;t request this, please ignore this email.


----==_mimepart_517dcd2d93927_71bc677870116dc
Date: Mon, 29 Apr 2013 01:30:21 +0000
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <517dcd2db365a_71bc677870118da@testsite-test.mail>

<p>Hello emailaddress@outlook.com!</p>

<p>A Request to change the password for this account has been received. If this is you, and you still want to change the password, you can do so by clicking on the link below.</p>

<p><a href="http://test.testsitethefuture.com/password/edit?reset_password_token=NysDaribCpgNySc5Nmog">Change my password</a></p>

<p>If you didn&#x27;t request this, please ignore this email.</p>


----==_mimepart_517dcd2d93927_71bc677870116dc--

Redirected to http://test.testsitethefuture.com/login
Completed 302 Found in 2520ms (ActiveRecord: 0.0ms)
Started GET "/login" for 174.xx.xxx.xx at 2013-04-29 01:30:22 +0000
Processing by Devise::SessionsController#new as HTML
  BlogPost Load (3.0ms)  SELECT `blog_posts`.* FROM `blog_posts` 
  Rendered devise/_links.erb (0.8ms)
  Rendered devise/sessions/new.html.erb within layouts/application (7.0ms)
  Rendered layouts/_shim.html.erb (0.0ms)
  Rendered layouts/_header.html.erb (2.2ms)
  Rendered layouts/_promo_bar.html.erb (1.2ms)
  Rendered layouts/_footer.html.erb (2.6ms)
Completed 200 OK in 49ms (Views: 35.9ms | ActiveRecord: 3.0ms)

关于我应该寻找什么的任何想法?

环境/test.rb

Myapp::Application.configure do
  config.cache_classes = false
  config.serve_static_assets = true
  config.static_cache_control = "public, max-age=3600"
  config.whiny_nils = true
  config.consider_all_requests_local = true
  config.action_controller.perform_caching = false
  config.action_dispatch.show_exceptions = false
  config.action_controller.allow_forgery_protection = false
  config.active_record.mass_assignment_sanitizer = :strict
  config.active_support.deprecation = :stderr
  config.action_mailer.default_url_options = {:host => 'myapp.com'}
  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 = {
      address: "smtp.gmail.com",
      port: 587,
      domain: "myapp.com",
      authentication: "plain",
      enable_starttls_auto: true,
      user_name: 'Admin@myapp.com',
      password: 'xxxxxxxxxxx'
  }
end

【问题讨论】:

  • 请有机会发布您的邮件配置
  • 您在productiondevelopment 中的config.mail 块中的设置未正确设置。
  • 如果我的邮件配置设置不正确,则不会发送任何电子邮件。除密码重置外,所有电子邮件都将发送出去。

标签: ruby-on-rails-3 devise


【解决方案1】:

检查配置文件中的 SMTP Mailer 设置,从日志中显示邮件发送正确但未送达,因为 SMTP 设置问题。

更正 smtp 设置并从控制台检查邮件

Ex:-

Notification.forgot_password("sample@test.com").deliver

【讨论】:

  • 查看我的问题,第一句话:我的设计控制器在发送电子邮件时工作正常,但有一个例外:发送重置密码说明电子邮件。另外,在开发环境上,重置密码说明邮件发送正常。
  • 是的,我已经看到了,因为只有我告诉我在控制台中尝试代码,在此之前检查 smtp 设置,如果您使用的是 gmail smtp 设置,请从邮件发送块中删除回复。即使日志显示邮件正在发送,如果 smtp 设置错误,它也不会将邮件发送到电子邮件。您使用的是什么操作系统?
【解决方案2】:

在 config/environments/test.rb 中使用 ActionMailer::Base.delivery_method = :smtp in config/environment.rb 行覆盖 ActionMailer::Base.delivery_method = :test

所以,添加那行 ActionMailer::Base.delivery_method = :smtp' from config/environment.rb 并将其放在 config/environments/test.rb 中。这允许您放置

ActionMailer::Base.delivery_method = :test in config/environments/test.rb.

注意:您必须重新启动服务器才能使这些更改生效。

在 config/environment.rb 中:

# Configuration for using SendGrid on Heroku
ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',
  :authentication => :plain,
  :user_name      => 'app[my app number]@heroku.com',
  :password       => '[something super secret]',
  :domain         => '[let's get this party started!.com]',
  :enable_starttls_auto => true
}
ActionMailer::Base.delivery_method = :smtp

为我工作。

【讨论】:

  • 您阅读我的问题了吗? 1)我没有使用 Heroku。 2) 我的 test.rb 中没有 ActionMailer::Base.delivery_method = :test 3) 我的 test.rb 中已经有 config.action_mailer.delivery_method = :smtp 4) 我没有使用 SendGrid 5) 我没有在 config/environment.rb 中有任何与邮件有关的内容
  • 是的,我阅读了您的问题,尝试在 config/environment.rb 中添加 ActionMailer::Base.delivery_method = :smtp。这与您的问题相似。我在heroku上创建了一个应用程序并遇到了同样的问题。我也解决了上面提到的问题。请检查
  • 将 ActionMailer::Base.delivery_method = :smtp 添加到 config/environment.rb 不起作用,并且根本不添加任何内容,因为该行已经在 /config/environments/test.rb .阅读我的问题
  • 好的,将 config/environment/test.rb 中的行更改为 ActionMailer::Base.delivery_method = :test 并请检查。还要在 config/environment.rb 中添加 ActionMailer::Base.delivery_method = :smtp
  • 我不会随意猜测。我已经有一个 environment/test.rb 文件。阅读它,以便您了解为什么您的建议不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-16
  • 2017-08-30
  • 1970-01-01
  • 2013-12-18
  • 2015-08-13
  • 2016-08-04
  • 1970-01-01
相关资源
最近更新 更多