【问题标题】:Devise - emails not being sent设计 - 未发送电子邮件
【发布时间】:2014-04-02 19:04:05
【问题描述】:

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

在 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>

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

【问题讨论】:

    标签: ruby-on-rails devise


    【解决方案1】:

    您可能没有正确设置电子邮件配置:

    只需在 'config/initializers/' 文件夹中创建一个文件 email.rb 并放入以下内容:

    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"
    

    希望对你有帮助:)

    【讨论】:

    • 嗨对不起,没有。我收到一个设计错误:Net::SMTPAuthenticationError in Devise::UnlocksController#create 534-5.7.9 Application-specific password required
    • 嘿,只需将您的电子邮件和密码放在 email.rb 中即可。你换过那个吗?将 替换为您的原始 gmail 用户名,将 替换为电子邮件帐户的密码。然后重启服务器。
    • 是的,我输入了我的电子邮件详细信息。
    • 我尝试了一个不同的电子邮件帐户,它正在工作。太感谢了!任何想法为什么我需要添加这个?我可以使用这些信息配置设备本身吗?
    • 如果真的对你有帮助,希望你能接受答案。
    猜你喜欢
    • 1970-01-01
    • 2015-09-08
    • 2016-08-04
    • 2011-12-28
    • 2013-05-14
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多