设计忘记密码未收到电子邮件

时间:2013-06-26 13:49:04

标签: ruby-on-rails devise ruby-on-rails-3.2

我面临设计忘记密码的问题。我没有收到任何电子邮件,虽然设计显示消息“您将收到一封电子邮件,其中包含有关如何在几分钟内重置密码的说明”。

Ruby-1.9.3 Rails 3.2设计2.2.4

我的环境/ development.rb

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"


ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:domain => 'xyz@gmail.com',
:user_name => 'xyz@gmail.com',
:password => 'abcde',
 }

我的环境.rb     ActionMailer :: Base.delivery_method =:smtp

我的intializers / devise.rb

config.mailer_sender = "xyz@gmail.com"

并且development.log显示

Sent mail to xyz@gmail.com (3205ms)
Date: Wed, 26 Jun 2013 23:33:01 +1000
From: xyz@gmail.com
Reply-To: x@gyzmail.com
To: xyz@gmail.com
Message-ID: <51caed8dd99a5_15365823b9268927@nbnco-U01.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello xyz@gmail.com!</p>

<p>Someone has requested a link to change your password. You can do this the    link below.</p>

<p><a href="http://localhost:3000/users/password     /edit?reset_password_token=zb1mZUEzxpymqE8qorDJ">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>

Redirected to http://localhost:3000/users/sign_in
Completed 302 Found in 3423ms (ActiveRecord: 0.0ms)

2 个答案:

答案 0 :(得分:2)

正如上面在开发模式中提到的那样,如果您对如何获得(并且可能想要覆盖该行为)感到好奇,请查看以下文件 配置/环境/ development.rb:

  #don't send emails in development
  config.action_mailer.perform_deliveries = false

当然最好使用一些mailtrap,但是如果你想快速查看邮箱中的邮件,只需将false更改为true,如果你当然配置了正确的邮件程序就可以了。

编辑:

这是我对gmail的配置并且它有效,没有域名参数,所以可能它正在制造麻烦:

config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :user_name            => '<login>',
      :password             => '<password>',
      :authentication       => 'plain',
      :enable_starttls_auto => true  }

Edit2:不要忘记重新启动服务器;)

答案 1 :(得分:0)

在使用您的配置进行开发时,不会发送电子邮件,但只会在日志中显示。您可以尝试使用以下服务: