セットアップ: 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
ニュースレターMailer.rb
class NewsletterMailer < ActionMailer::Base
default from: "some@email.com"
def confirmation(email)
mail to: email,
subject: "Welcome"
end
end
繰り返しますが、これは開発でのみ機能し、本番環境では機能しません。データベースを Mysql2 に変更しようとしましたが、同じエラーが発生します。
私のdatabase.yml:
production:
adapter: postgresql
encoding: unicode
reconnect: false
database: app_production
pool: 5
username: user
password: secret
host: localhost
メーリングには、mandrill または gmail で smtp を使用します。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
更新: 送信がインデックスに保存されることがわかりました。だから私はDBが機能していると思います。
何かアドバイス?ありがとう