Errno::Econnrefused: Connection Refused - Connect(2) for Action Mailer

Connection refused - connect(2) Ruby on Rails Mail Setup

I see you have tried identical settings on both servers but are having problems only on your production / non-local host environment.

This points to an issue with the network configuration of the environment itself.

In the command line on your same server as your application, try the following command

telnet smtp.gmail.com 587

You should see something like the following

telnet smtp.gmail.com 587
Trying 173.194.79.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP dd5sm276863pbc.85 - gsmtp

If you do not see this, you will most likely get a connection error. This means your machine does not have access to the gmail server. Likely problems are a) general outbound network connectivity, b) firewalls specifically blocking all outbound connections c) firewalls blocking/allowing connections to particular ports or hosts

If this does not work, also try the following ports in place of 587

telnet smtp.gmail.com 465
telnet smtp.gmail.com 25

If one of these is more successful, change your mail server settings to use accordingly.

Edit: We had quite a bit of trouble using Gmail and then Gmail with our custom domain. One thing that can help is to remove the :domain line from your configuration file, try without it.

For reference, here is my Gmail config in prod using our custom domain hosted by Gmail:

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
}

Also, if you do have 2-factor authentication enabled on your Gmail account, you might want to disable it and try this again just to confirm it is not complicating the issue.

Using mail form in rails for contact: Errno::ECONNREFUSED: Connection refused - connect(2)

I was able to fix this issue. Stupid me forgot to add the gmail mailer. I didn't realize I needed it with mail form. The tutorial I used never put in that type of information.

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'myname@gmail.com',
password: 'mypassword',
authentication: 'plain',
enable_starttls_auto: true }

Errno::ECONNREFUSED (Connection refused - connect(2) for nil port 587): for Rails on Heroku

Set your environment variables, make sure your SES endpoint is in production mode and you should be good.



Related Topics



Leave a reply



Submit