繁体   English   中英

Errno :: ECONNREFUSED(连接被拒绝-“ localhost”端口587的connect(2))操作邮件

[英]Errno::ECONNREFUSED (Connection refused - connect(2) for “localhost” port 587) action mailer

该应用发送电子邮件时出现此错误:

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">]

我的development.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

Environment.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 <ApplicationMailer

  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,Rails 4.2.3上的Server Puma ...

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

我试图将端口更改为:25和465,但无法正常工作

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

这只是一个错字! ;-)

从错误中可以看到,尝试的连接在正确的端口上,但是在错误的主机上,因此需要在主机名config上搜索问题(至少,这是我找到它的方式)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM