【问题标题】:Devise - Setting up mailer设计 - 设置邮件程序
【发布时间】:2011-09-15 13:31:31
【问题描述】:

我已经设计实现了一个 rails 3 应用程序。我正在尝试让邮件程序与设计一起使用。我目前的情况是,当我输入一个电子邮件地址时,这是我设置的默认 gmail 帐户。它会将我重定向回“登录”页面并给我一个通知“说我将很快收到指令”,但是这些指令没有被发送。我和在RubyForum 上发帖的人遇到了同样的问题,我读了这篇文章,但它根本没有帮助。我的 config/environment/development.rb 如下所示:

Project::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # In the development environment your application's code is reloaded on
  # every request.  This slows down response time but is perfect for development
  # since you don't have to restart the webserver when you make code changes.
  config.cache_classes = false

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_view.debug_rjs             = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin

  #SMTP
  config.action_mailer.default_url_options = { :host => 'localhost' }  
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :user_name            => 'k0903421@gmail.com',
  :password             => '',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

end

我有什么遗漏吗?

当我被重定向回登录页面时,我会进入控制台:

Sent mail to k0903421@gmail.com (30181ms)
Date: Thu, 15 Sep 2011 14:48:06 +0100
From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com
To: k0903421@gmail.com
Message-ID: <4e720216bf59b_3b215d477ae963de@dj.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

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

<p>Someone has requested a link to change your password, and you can do this through the link below.</p>

<p><a href="http://localhost/users/password/edit?reset_password_token=fqJXk6JbotIxIv3Awq1s">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://0.0.0.0:3000/login
Completed 302 Found in 32658ms


Started GET "/login" for 127.0.0.1 at 2011-09-15 14:48:36 +0100
  Processing by Devise::SessionsController#new as HTML
  SQL (0.7ms)  describe `roles_users`
  SQL (0.9ms)  describe `roles_users`
Rendered layouts/_stylesheets.html.erb (0.9ms)
Rendered layouts/_javascripts.html.erb (1.6ms)
Rendered layouts/_header.html.erb (0.8ms)
Rendered layouts/_logo.html.erb (0.7ms)
Rendered layouts/_errors.html.erb (1.8ms)
Rendered devise/sessions/new.html.erb within layouts/application (62.0ms)
Completed 200 OK in 150ms (Views: 68.9ms | ActiveRecord: 1.6ms)

设计密码控制器

def create
    self.resource = resource_class.send_reset_password_instructions(params[resource_name])

    if successful_and_sane?(resource)
      set_flash_message(:notice, :send_instructions) if is_navigational_format?
      respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
    else
      respond_with_navigational(resource){ render_with_scope :new }
    end
  end

【问题讨论】:

  • 我会尽快更改您的密码(永远不要在任何地方在线列出)。开发日志显示什么?
  • X_x 是偶然的。不用担心它是我设置的测试电子邮件帐户。谢谢你
  • 我已编辑我的帖子以显示我在控制台中收到的内容
  • 将此选项设置为 true,以便您可以在开发日志中看到邮件程序错误:config.action_mailer.raise_delivery_errors = false
  • 我收到以下错误:Timeout::Error in Devise::PasswordsController#create execution expired

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


【解决方案1】:

问题来了:

From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com

更改config/initializers/devise.rb中的邮箱信息

【讨论】:

  • 那么我应该把From: please-change-me-at-config-initializers-devise@example.com这个改成我的gmail帐户吗?
  • 记得在生产模式下运行服务器,否则邮件只会显示在控制台中,实际上不会发送。
  • 我以前在开发模式下工作过。似乎不明白为什么这不起作用。我什至尝试对 gmail 执行 ping 操作:ping smtp.gmail.com 并且连接超时
  • 我设法修复了我的错误。我安装了 mailcatcher github.com/sj26/mailcatcher 并这样做
猜你喜欢
  • 2017-04-19
  • 2012-10-16
  • 1970-01-01
  • 2017-07-07
  • 2014-09-14
  • 2015-01-27
  • 1970-01-01
  • 2014-01-01
  • 2012-11-22
相关资源
最近更新 更多