【问题标题】:Errno::ECONNREFUSED - Connection refused - connect(2) for "localhost" port 25:Errno::ECONNREFUSED - 连接被拒绝 - “localhost”端口 25 的连接(2):
【发布时间】:2016-07-16 14:09:18
【问题描述】:

我正在尝试使用 devise 在 rails 4 中使用动态电子邮件服务器设置重置密码。

my_mailer.rb

class MyMailer < Devise::Mailer
    helper :application
    include Devise::Controllers::UrlHelpers
    default template_path: 'devise/mailer' 

    def reset_password_instructions(record, token, opts={})
        # Has been dynamically set in the mailer_set_url_options of application_controller.rb
        # opts[:host] = Setup.email_url
        opts[:address] = Setup.email_address
        opts[:port] = Setup.email_port
        opts[:domain] = Setup.email_domain
        opts[:from] = Setup.email_username
        super
    end
end

但是遇到同样的错误,可能是什么问题,任何帮助都会非常有帮助,谢谢 :)

【问题讨论】:

  • 在此处发布您的 smtp 配置
  • @RajarshiDas 我添加了截图看看它。它实际上让一切都搞砸了,我猜从设计方面它不是压倒一切的。
  • 你需要像guides.rubyonrails.org/…一样发布环境smtp配置
  • 谢谢你我知道我们必须这样做,但我不想把它设置成我的 smtp 配置是动态的。

标签: ruby-on-rails-4 devise smtp devise-recoverable


【解决方案1】:

首先根据截图

我认为您正在使用 gmail 作为提供者。

请转到环境文件(development.rbproduction.rb)。我猜你正在使用开发环境。

转到文件config/environments/development.rb

config.action_mailer.default_url_options = { :host => "my.website.com" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'website.com',
    user_name:            'user@website.com',
    password:             'password',
    authentication:       'plain',
    enable_starttls_auto: true
}

请参考ThisDoc

希望对你有帮助

【讨论】:

  • 我真的很抱歉告诉你,但这就是我不想那样使用它的问题。 :(
  • 动态是什么意思?您是否从任何 api 获取服务配置
  • 在我的应用程序本身中,我们将获取配置并使用该配置本身。
【解决方案2】:

我没有使用 Devise,但在尝试动态更改我的应用程序邮件的 smtp_settings 时遇到了同样的错误。 在我的情况下,设置来自数据库。 我让它工作的方法是使用ActionMailerafter_action 回调。并合并我的邮件投递方式的设置

这是一个例子:

after_action do
 self.delivery_method = SETTING_FROM_DB.delivery_method
 settings = {
   address: SETTING_FROM_DB.address,
   port: SETTING_FROM_DB.port
   # More setting if needed
   }
 self.mail.delivery_method.settings.merge! settings
end

【讨论】:

    猜你喜欢
    • 2021-06-14
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 2012-04-01
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多