2013-04-29 145 views
1

Rails的3.2.13和Ruby 1.9.3重置密码电子邮件没有被设计

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

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

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"=>"[email protected]"}, "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` = '[email protected]' 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 [email protected] (133ms) 
Date: Mon, 29 Apr 2013 01:30:21 +0000 
To: [email protected] 
Message-ID: <[email protected]> 
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: <[email protected]> 

Hello [email protected]! 

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: <[email protected]> 

<p>Hello [email protected]!</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: '[email protected]', 
     password: 'xxxxxxxxxxx' 
    } 
end 
+0

任何机会,你可以发布你的邮件配置请 – Richlewis 2013-04-29 14:15:43

+0

你在'生产'或'开发''config.mail'块设置没有设置正确。 – David 2013-04-29 15:01:03

+0

如果我的邮件配置设置不正确,则不会发送邮件。除了密码重置,所有电子邮件都会发送出去。 – EastsideDeveloper 2013-04-29 18:51:40

回答

0

检查SMTP邮件程序设置在您的配置文件,从数据显示,邮件发送正确的,但它没有提供,因为SMTP设置问题。

更正SMTP设置,并从控制台

Ex:- 

Notification.forgot_password("[email protected]").deliver 
+0

看到我的问题,第一句话:我的设计控制器工作正常发送电子邮件,但有一个例外:发送重置密码指令电子邮件。此外,在开发环境中,重置密码指令电子邮件发送正常。 – EastsideDeveloper 2013-04-30 21:17:59

+0

是的,我见过因为只有我告诉我试着在控制台中的代码和之前检查smtp设置,如果您使用Gmail的SMTP设置,请删除邮件发送块的答复。即使日志显示邮件正在发送,如果smtp设置错误,它也不会将邮件发送到电子邮件。你使用的是什么操作系统? – 2013-05-02 11:33:23

0

检查邮包有ActionMailer::Base.delivery_method = :smtp in config/environment.rb在配置/环境/ 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 

为我工作。

+0

您是否看过我的问题? 1)我没有使用Heroku。 2)我没有ActionMailer :: Base.delivery_method =:测试在我的test.rb 3)我已经有config.action_mailer.delivery_method =:我的test.rb中的smtp 4)我没有使用SendGrid 5)我没有有任何与config/environment.rb中的邮件相关 – EastsideDeveloper 2013-05-01 07:51:42

+0

是的,我读过你的问题尝试添加** ActionMailer :: Base.delivery_method =:smtp **在** config/environment.rb **中。它与你的问题类似。我在heroku上创建了一个应用程序,并面临同样的问题。我也解决了上述问题。请检查 – 2013-05-01 08:07:23

+0

添加ActionMailer :: Base.delivery_method =:smtp到config/environment。rb不起作用,并且根本不添加任何东西,因为该行已经在/config/environments/test.rb中。阅读我的问题 – EastsideDeveloper 2013-05-01 08:39:08

相关问题