1

I have a Ruby on Rails 4.1 application running with nginx + Unicorn. When I try to send email that way:

ActionMailer::Base.smtp_settings = {  
  :openssl_verify_mode => 'none'
}
ActionMailer::Base.mail(:from => "info@my_ip", #I don't have a domain name.
                        :to => "my_email", 
                        :subject => subject, :body => body).deliver

This produce the error:

Connection refused - connect(2) for "localhost" port 25

My nginx configuration:

worker_processes 1;
user michael michael;
pid /tmp/nginx.pid;

events {
  worker_connections 128;
  accept_mutex off; 
}

http {
  include mime.types;

  default_type application/octet-stream;

  sendfile on;

  tcp_nopush on; 
  tcp_nodelay off; 

  gzip on;

  upstream msystem_server {
    server unix:/srv/msystem/shared/.unicorn.sock fail_timeout=0;
  }

  server {
    listen 80 default deferred; 
    client_max_body_size 10M;
    server_name my_ip;
    keepalive_timeout 5;
    root /srv/msystem/current/public;

    try_files $uri/index.html $uri.html $uri @msystem;

    location @msystem {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;

      proxy_redirect off;

      proxy_pass http://msystem_server;
    }
  }
}

Sorry for my English. I don't know, what else to say. But stackoverflow says, that I should.

Michael
  • 548
  • 8
  • 30

1 Answers1

1

It seems like you don't have any mailer service running on the port 25.

From the documentation:

:port - On the off chance that your mail server doesn't run on port 25, you can change it.

Reading documentation further:

delivery_method - Defines a delivery method. Possible values are :smtp (default), :sendmail, :test, and :file.

So if you have it set to :smtp you may want to change the port to 587, which is now almost default for the main external services. If you set :sendmail however, you should set the corresponding port for your local service.

Kamil Lelonek
  • 14,592
  • 14
  • 66
  • 90
  • I don't understand. May be I forget to configure something. I didn't run any mail service. I thought Rails do it automatically. – Michael Oct 24 '14 at 06:08
  • I have only one setting in `config/environment/production.rb`: `config.action_mailer.default_url_options = { :host => "http://my_ip" }` – Michael Oct 24 '14 at 06:09
  • I see. Unfortunately it's not done automagically and you should follow: http://stackoverflow.com/questions/4929680/setting-up-a-gmail-account-to-work-with-actionmailer-in-rails-3/ – Kamil Lelonek Oct 24 '14 at 07:58