Ruby on rails 4 错误号::ECONREFUSSED-连接被拒绝-连接(2)用于;“本地主机”;端口25:

Ruby on rails 4 错误号::ECONREFUSSED-连接被拒绝-连接(2)用于;“本地主机”;端口25:,ruby-on-rails-4,devise,smtp,devise-recoverable,Ruby On Rails 4,Devise,Smtp,Devise Recoverable,我正在尝试使用Desive在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, toke

我正在尝试使用Desive在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
my_mailer.rb
类MyMailer
但是,如果遇到同样的错误,会有什么问题?任何帮助都会非常有用。谢谢:)

首先根据屏幕截图

我认为你正在使用
gmail
作为一个提供者

请转到环境文件(
development.rb
production.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
}
请参阅


希望它可以帮助您

我没有使用Desive,但在尝试动态更改我的应用程序邮件程序的smtp\u设置时出现了相同的错误。 在我的例子中,设置来自数据库。 我让它工作的方法是使用
after\u action
回调
ActionMailer
。以及合并我的邮件传递方法的设置

以下是一个例子:

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

发布您的smtp配置here@RajarshiDas我添加了截图,只是看了一下。它实际上把一切都搞砸了,我想从设计的角度来看,它不是最重要的。你需要发布环境smtp配置,比如谢谢你,我知道我们必须这样做,但我不想将其设置为我的smtp配置是动态的。我很抱歉告诉您,这就是问题所在,我不想这样使用它:(动态是什么意思?您是否从我的应用程序本身的任何API获取服务配置?我们将获取配置并使用该配置本身。