我正在使用设计在rails 3上进行身份验证。登录,注销,注册工作正常,但忘记密码时没有任何反应。当我点击忘记密码链接时,它会将我带到http://localhost:3000/users/password/new
链接,然后我会收到一个表格,询问我的电子邮件地址和发送给我重置密码说明按钮,但是当我点击该按钮时,我需要{{1但我没有收到有关重置密码的邮件。
在控制台上,我可以看到以下内容:
http://localhost:3000/users/sign_in
但我在收件箱中看不到邮件。
以下是我的config / initializer / devise.rb文件的代码:
Sent mail to nikitasalunkhe.3@gmail.com (968ms)
Date: Tue, 05 Jun 2012 13:14:22 +0530
From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com
To: nikitasalunkhe.3@gmail.com
Message-ID: <4fcdb8d6de776_dd624e71f0a78a7@user-G41MT-S2.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Hello nikitasalunkhe.3@gmail.com!</p>
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
<p><a href="http://localhost:3000/users/password/edit?reset_password_token=gUB8L9nWNikjVJpnhbDW">Change my password</a></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
这是development.rb文件代码:
Devise.setup do |config|
config.mailer_sender = "nikitasalunkhe.3@gmail.com"
config.mailer = "Devise::Mailer"
require 'devise/orm/active_record'
config.case_insensitive_keys = [ :email ]
config.stretches = 10
config.use_salt_as_remember_token = true
config.reset_password_keys = [ :email ]
我应该做些什么改变才能让它发挥作用?
答案 0 :(得分:1)
您是否安装了本地邮件程序守护程序?我最好的解决方案是使用这样的gmail smtp(使用你的设置):
在config / environments / development.rb中:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'mondomaine.com',
:user_name => 'smtp@mondomaine.com',
:password => 'mypassword',
:authentication => 'plain',
:enable_starttls_auto => true }
并删除你的行:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
在生产模式下,您将拥有一个本地邮件服务器作为后缀。
答案 1 :(得分:1)
另一种解决此问题的方法是创建一个文件 “config / initializer / setup_mail.rb”
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "googlemail.com",
:user_name => "ayushcshah@gmail.com",
:password => "secret_password",
:authentication => "plain",
:enable_starttls_auto => true
}
答案 2 :(得分:0)
解决了这个问题......在我的development.rb文件中进行了一些更改,如下所示:
require 'tlsmail'
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:tls => true,
:domain => 'gmail.com', #you can also use google.com
:authentication => :plain,
:user_name => "nikitasalunkhe.3@gmail.com",
:password => "seceret_password"
}
答案 3 :(得分:-2)
config.action_mailer.default_url_options = { :host => 'my@gmail.com' }
而不是localhost:3000,请尝试提供您的Gmail帐户名称。