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

百般思念 提交于 2019-11-28 11:24:18

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.

You gave the domain as localhost. The domain should be gmail.com. Please change Your config/initializers/setup_mail.rb to

ActionMailer::Base.smtp_settings = { :address => 'smtp.gmail.com', :port => 587, :domain => 'gmail.com', :user_name => 'EMAIL_ADDRESS@gmail.com', :password => 'pass', :authentication => 'plain', :enable_starttls_auto => true }

And in production.rb. You don't need to configure for email address. The following lines are enough.

config.action_mailer.default_url_options = { :host => 'app_url' }
config.action_mailer.delivery_method = :smtp
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!