设计 - 未发送电子邮件

时间:2014-04-02 10:51:52

标签: ruby-on-rails devise

我正在尝试实现设计的自动锁定功能。我的应用程序仍在开发中。我输入了一个不正确的密码来激活自动锁定,但工作正常但我在设置电子邮件以解锁帐户时遇到了问题。

在config / environments / development.rb中我有:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

在config / initializers / devise.rb中我有

config.mailer_sender = 'sender@mail.com'
config.mailer = 'Devise::Mailer'

然后在同一个文件中进一步向下:

  # ==> Configuration for :lockable
  # Defines which strategy will be used to lock an account.
  # :failed_attempts = Locks an account after a number of failed attempts to sign in.
  # :none            = No lock strategy. You should handle locking by yourself.
   config.lock_strategy = :failed_attempts

  # Defines which key will be used when locking and unlocking an account
   config.unlock_keys = [ :email ]

  # Defines which strategy will be used to unlock an account.
  # :email = Sends an unlock link to the user email
  # :time  = Re-enables login after a certain amount of time (see :unlock_in below)
  # :both  = Enables both strategies
  # :none  = No unlock strategy. You should handle unlocking by yourself.
   config.unlock_strategy = :email

  # Number of authentication tries before locking an account if lock_strategy
  # is failed attempts.
   config.maximum_attempts = 5

  # Time interval to unlock the account if :time is enabled as unlock_strategy.
  # config.unlock_in = 1.hour

  # Warn on the last attempt before the account is locked.
   config.last_attempt_warning = true

  # ==> Configuration for :recoverable
  #
  # Defines which key will be used when recovering the password for an account
   config.reset_password_keys = [ :email ]

  # Time interval you can reset your password with a reset password key.
  # Don't put a too small interval or your users won't have the time to
  # change their passwords.
  config.reset_password_within = 6.hours

根据我的服务器日志,电子邮件已发送。我看到以下内容:

Sent mail to receiver@mail.com (48.3ms)
Date: Wed, 02 Apr 2014 11:25:41 +0100
From: sender@mail.com
Reply-To: sender@mail.com
To: receiver@mail.com
Message-ID: <533be5a583e8d_9b624e20d76904fc@ubuntuSheeka.mail>
Subject: Unlock Instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello receiver@mail.com!</p>

<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>

<p>Click the link below to unlock your account:</p>

<p><a href="http://localhost:3000/users/unlock?unlock_token=yQS9XYp4twxGr1TXMywx">Unlock my account</a></p>

问题是我没有在收件箱中看到邮件。任何有关这方面的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可能无法正确设置电子邮件配置:

只需在“email.rb”文件夹中创建文件config/initializers/,然后输入以下内容:

ActionMailer::Base.delivery_method=:smtp
ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => "587",
  :domain => "gmail.com",
  :authentication => :login,
  :user_name => "<your email username>",
  :password => "<your email passowrd>",
  :enable_starttls_auto => true
}
ActionMailer::Base.perform_deliveries = true 
ActionMailer::Base.raise_delivery_errors = true 
ActionMailer::Base.default :charset => "utf-8"
ActionMailer::Base.default :content_type => "text/html"
ActionMailer::Base.default_url_options[:host] = "localhost:3000"

希望有所帮助:)