1

设置:带有 Ubuntu 12.04、Apache、PhusionPassenger、Rail 3.2.12、Postgresql 的 VPS

我想用我的应用程序发送确认邮件。在开发模式下一切正常,用户收到一封邮件,但在生产中我收到此错误(日志):

Started POST "/newsletters" for 1XX.16X.30.XX at 2013-02-26 09:22:47 +0000
Processing by NewslettersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"XXXXXXXXXXXXX=",
"newsletter"=>{"name"=>"Test", "email"=>"test@example.com"}, "commit"=>"Submit"}

  Rendered newsletter_mailer/confirmation.text.erb (0.4ms)

Sent mail to test@example.com (44ms)
Completed 500 Internal Server Error in 134ms

Errno::ECONNREFUSED (Connection refused - connect(2)):
  app/controllers/newsletters_controller.rb:45:in `create'

所以我想,错误应该在 newsletters_controller.rb 中(第 45 行被标记):

def create
    @newsletter = Newsletter.new(params[:newsletter])

    if @newsletter.save
      NewsletterMailer.confirmation(@newsletter.email).deliver ### line 45
      flash[:success] = 'It works!'
      redirect_to root_path
    else
      flash[:error] = 'Error!'
      render action: "new"
    end
end

NewsletterMailer.rb

class NewsletterMailer < ActionMailer::Base
  default from: "some@email.com"

  def confirmation(email)
    mail to: email,
         subject: "Welcome"
  end
end

同样,它仅在开发中有效,而在生产中无效。我也尝试将数据库更改为 Mysql2,但出现同样的错误。

我的数据库.yml:

production:
  adapter: postgresql
  encoding: unicode
  reconnect: false
  database: app_production
  pool: 5
  username: user
  password: secret
  host: localhost

对于邮件,我使用 smtp 和 mandrill 或 gmail。Gmail 设置在另一个应用程序中运行良好...

我的环境.rb

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
LandingPage::Application.initialize!

LandingPage::Application.configure do 
  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
    :address   => "smtp.mandrillapp.com",
    :port      => 587, # or 25
    :enable_starttls_auto => true, # detects and uses STARTTLS
    :user_name => "user",
    :password  => "password",
    :authentication => 'login' # Mandrill supports 'plain' or 'login'
}
end

更新:我发现提交的内容保存在我的索引中。所以我猜数据库可以工作。

有什么建议吗?谢谢

4

1 回答 1

0

我通过从 mandrill 更改新密码(api-key)解决了我的问题。仍然不知道问题是什么,因为旧的它在开发模式下工作......

工作环境:

YourApp::Application.configure do
  config.action_mailer.smtp_settings = {
    :address   => "smtp.mandrillapp.com",
    :port      => 587,
    :enable_starttls_auto => true,
    :user_name => "MANDRILL_USERNAME",
    :password  => "MANDRILL_PASSWORD", # SMTP password is any valid API key
    :authentication => 'login'
  }
于 2013-02-27T18:20:51.770 回答