2013-04-29 146 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

相關問題