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'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'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)
我应该寻找什么想法?
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
答案 0 :(得分:0)
检查配置文件中的SMTP邮件程序设置,从日志显示邮件正在正常发送但由于SMTP设置问题而未送达。
更正smtp设置并从控制台检查邮件
Ex:-
Notification.forgot_password("sample@test.com").deliver
答案 1 :(得分:0)
让行ActionMailer::Base.delivery_method = :smtp in config/environment.rb
覆盖config / environments / test.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
为我工作。