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',
 }

我的 environment.rb ActionMailer::Base.delivery_method = :smtp

我的初始化器/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)
4

2 回答 2

2

正如上面提到的,在开发模式下,邮件并没有真正发送,如果您好奇这是如何获得的(并且可能想要覆盖该行为),请查看以下文件 config/environments/development.rb:

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

当然,使用一些邮件陷阱会更好,但如果您只想快速查看邮箱中的邮件,只需将 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:别忘了重启你的服务器;)

于 2013-06-26T14:07:47.280 回答
0

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

于 2013-06-26T13:58:14.257 回答