【问题标题】:Email error with Rails + nginx + UnicornRails + nginx + Unicorn 的电子邮件错误
【发布时间】:2014-10-24 13:44:41
【问题描述】:

我有一个使用 nginx + Unicorn 运行的 Ruby on Rails 4.1 应用程序。当我尝试以这种方式发送电子邮件时:

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

这会产生错误:

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

我的 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;
    }
  }
}

对不起我的英语。 不知道,还有什么好说的。但是stackoverflow说,我应该。

【问题讨论】:

    标签: ruby-on-rails ruby email nginx unicorn


    【解决方案1】:

    您似乎没有在25 端口上运行任何邮件服务。

    来自documentation

    :port - 如果您的邮件服务器没有在端口 25 上运行,您可以更改它。

    进一步阅读文档:

    delivery_method - 定义交付方法。可能的值为 :smtp(默认)、:sendmail、:test 和 :file。

    因此,如果您将其设置为:smtp,您可能需要将端口更改为587,这几乎是主要外部服务的默认设置。但是,如果你设置了:sendmail,你应该为你的本地服务设置相应的端口。

    【讨论】:

    • 我不明白。可能是我忘记配置一些东西。我没有运行任何邮件服务。我以为 Rails 会自动完成。
    • 我在config/environment/production.rb中只有一个设置:config.action_mailer.default_url_options = { :host => "http://my_ip" }
    • 我明白了。不幸的是,它不是自动完成的,您应该遵循:stackoverflow.com/questions/4929680/…
    猜你喜欢
    • 1970-01-01
    • 2012-05-29
    • 2015-05-21
    • 2010-10-10
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    相关资源
    最近更新 更多