【问题标题】:devise forgot password email not received设计忘记密码电子邮件未收到
【发布时间】:2013-06-23 16:51:37
【问题描述】:

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

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

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

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

  • 感谢您的回复。我已将 raise_delivery_errors 标志设置为 true,并且可以看到此错误:Net::SMTPAuthenticationError in Devise::PasswordsController#create 535-5.7.8 用户名和密码不是接受
【解决方案2】:

正如上面在开发模式中所提到的,邮件并不是真正发送的,如果您好奇它是如何获得的(并且可能想要覆盖该行为),请查看以下文件 配置/环境/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:别忘了重启你的服务器;)

【讨论】:

  • 感谢您的回复。我已将 raise_delivery_errors 标志设置为 true,并且可以看到此错误:Net::SMTPAuthenticationError in Devise::PasswordsController#create 535-5.7.8 用户名和密码不是接受
  • 我已经测试了这些设置,它可以在没有域的情况下工作(或使用gmail.com,但不能使用example.com,至少除非你在该域中有服务器;)),所以删除该行并将其删除应该没问题。
  • 感谢 zrl3dx 的回复。我根据你给我的内容验证了我的设置并从那里删除了域。一次又一次地尝试。我终于通过访问此 url 并更改用户偶然发现了这个问题setup_mail.rb 中的名称和密码
猜你喜欢
  • 1970-01-01
  • 2011-09-20
  • 2015-06-22
  • 2013-03-04
  • 1970-01-01
  • 2016-08-31
  • 2015-04-14
  • 2018-08-17
  • 2011-02-19
相关资源
最近更新 更多