简体   繁体   中英

Post and Errno::ECONNREFUSED (Connection refused - connect(2))

I set up a contact form and posted something. And then I got an error message.

Errno::ECONNREFUSED (Connection refused - connect(2)):

I have no idea how to solve this. Could you help me?

☆heroku logs

013-12-17T13:14:55.445509+00:00 app[web.1]: Started POST "/contacts" for 118.237.94.47 at 2013-12-17 13:14:55 +0000
2013-12-17T13:14:55.450507+00:00 app[web.1]: Processing by ContactsController#create as HTML
2013-12-17T13:14:55.450838+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"2e9zz3cX0tZwYTZhaPbRRYQuZrGi31fZk4OjjF7sdeo=", "contact"=>{"name"=>"荒牧さん", "email"=>"sun@gmail.com", "content"=>"どうなんすか!"}, "commit"=>"Create Contact"}
2013-12-17T13:14:55.549141+00:00 app[web.1]:   Rendered contact_mailer/sent.text.erb (0.6ms)
2013-12-17T13:14:55.573616+00:00 heroku[router]: at=info method=POST path=/contacts host=www.tsundoku-buster.jp fwd="118.237.94.47" dyno=web.1 connect=2ms service=136ms status=500 bytes=643
2013-12-17T13:14:55.570589+00:00 app[web.1]: 
2013-12-17T13:14:55.570589+00:00 app[web.1]: Sent mail to suncountry99@gmail.com (16ms)
2013-12-17T13:14:55.570797+00:00 app[web.1]: Completed 500 Internal Server Error in 120ms
2013-12-17T13:14:55.572327+00:00 app[web.1]: 
2013-12-17T13:14:55.572327+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2013-12-17T13:14:55.572327+00:00 app[web.1]:   app/controllers/contacts_controller.rb:6:in `create'

☆contacts_controller

 #encoding: utf-8 
class ContactsController < ApplicationController
      def create
       @contact = Contact.new(params[:contact])
       if @contact.save
        ContactMailer.sent(@contact).deliver
        redirect_to static_pages_contact_path, :notice => 'お問い合わせありがとうございました。'
      else
        render static_pages_contact_path, :alert => 'お問い合わせに不備があります。'
      end
     end
end

It looks like the contact controller is trying to send an email. In fact, from the logs I see the ContactMailer.sent method was called.

Heroku does not allow you to send emails using the internal SMTP. You need to use one of the Heroku add-on.

See the article Sending Email from Your App . The majority of Heroku email add-ons, such as SendGrid, are very straightforward to integrate in your Rails app.

i faced the same error, and it was because elasticsearch service not running. simply did: sudo service elasticsearch start

I had the same problem and it was cause by fail2ban. Just edit your /etc/fail2ban/jail.local file and disable [ssh] and [ssh-ddos] by setting enabled = false in the jail.local file.

$ sudo nano /etc/fail2ban/jail.local

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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