【问题标题】:Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 587) action mailerErrno::ECONNREFUSED(连接被拒绝 - “localhost”端口 587 的连接(2))操作邮件
【发布时间】:2016-01-18 18:44:16
【问题描述】:

当应用程序发送电子邮件时出现此错误:

Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 587):
  app/controllers/incidents_controller.rb:66:in `block in create'
  app/controllers/incidents_controller.rb:62:in `create'


  Rendered /home/jeremymontesinos/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (3.4ms)
  Rendered /home/jeremymontesinos/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.9ms)
  Rendered /home/jeremymontesinos/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms)
  Rendered /home/jeremymontesinos/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (16.8ms)
Cannot render console with content type multipart/form-dataAllowed content types: [#<Mime::Type:0x000000033b4ef0 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, #<Mime::Type:0x000000033b4bf8 @synonyms=[], @symbol=:text, @string="text/plain">, #<Mime::Type:0x000000033ad330 @synonyms=[], @symbol=:url_encoded_form, @string="application/x-www-form-urlencoded">]

我的开发.rb:

config.action_mailer.default_url_options = {:host => "localhost"}
config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
  adress: 'auth.smtp.1and1.fr',
  port: '587',
  user_name: 'foo@bar.fr',
  password: 'password',
  authentication: :plain,
  enable_starttls_auto: true}
  config.action_mailer.raise_delivery_errors = true

环境.rb:

# Load the Rails application.
require File.expand_path('../application', __FILE__)
ActionMailer::Base.default :content_type => "text/html"

# Initialize the Rails application.
Rails.application.initialize!

我的控制器(我发送电子邮件的命令):

  def create
    @incident = Incident.new(incident_params)
    @incident.user_id ||= current_user.id
    @incident.incident_state_id_for_user = 1
    @incident.incident_state_id_for_tech = 1


    respond_to do |format|
      if @incident.save
    @response = Response.new(content: "Incident créé par #{current_user.name} #{current_user.surname}", incident_id: @incident.id, sender_id: @incident.user_id)
    @response.save!
        AppMailer.incident_created.deliver_now
        format.html { redirect_to @incident, notice: 'Incident crée.' }
        format.json { render :show, status: :created, location: @incident }
      else
        format.html { render :new }
        format.json { render json: @incident.errors, status: :unprocessable_entity }
      end
    end
  end

App_mailer.rb: 类 AppMailer

  default from: "foo@bar.fr"

  def incident_created()

    mail(to: "bar@baz.com", subject: "Succefull !", body: "You're really cool!")

  end

end

还有application_mailer.rb:

class ApplicationMailer < ActionMailer::Base
  default from: "foo@bar.fr" #Here is a fake mail adress
  layout 'mailer'
end

所以我使用 LinuxMint 17.2、Server Puma on rails、rails 4.2.3 ...

编辑:我尝试使用 telnet auth.smtp.1and1.fr 587 ping 服务器,它可以工作

我尝试将端口更改为:25 和 465,但它不起作用

【问题讨论】:

  • 它看起来像是一个错误的主机名 (localhost) 而不是端口问题...
  • adress?不应该是address
  • 天哪!谢谢!

标签: ruby-on-rails ruby ruby-on-rails-4


【解决方案1】:

将您的development.rb adress 配置更改为address

这只是一个错字! ;-)

从错误中可以看出,尝试的连接在正确的端口上,但在错误的主机上,所以问题是在主机名配置上搜索(至少,我是这样找到的)

【讨论】:

    猜你喜欢
    • 2016-07-16
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 2016-12-05
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多