简体   繁体   English

Rails + nginx + Unicorn的电子邮件错误

[英]Email error with Rails + nginx + Unicorn

I have a Ruby on Rails 4.1 application running with nginx + Unicorn. 我有一个运行nginx + Unicorn的Ruby on Rails 4.1应用程序。 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: 我的nginx配置:

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. 但是stackoverflow说,我应该。

It seems like you don't have any mailer service running on the port 25 . 看来您在端口25上没有任何邮件服务运行。

From the documentation : 文档中

:port - On the off chance that your mail server doesn't run on port 25, you can change it. :port-如果您的邮件服务器不在端口25上运行,则可以更改它。

Reading documentation further: 进一步阅读文档:

delivery_method - Defines a delivery method. delivery_method-定义一种传递方法。 Possible values are :smtp (default), :sendmail, :test, and :file. 可能的值为:smtp(默认值)、: sendmail,:test和: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. 因此,如果将其设置为:smtp ,则可能需要将端口更改为587 ,这对于主要的外部服务现在几乎是默认设置。 If you set :sendmail however, you should set the corresponding port for your local service. 但是,如果设置:sendmail ,则应为本地服务设置相应的端口。

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

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