仅限生产中的邮件错误

设置:VPS与Ubuntu 12.04,Apache,PhusionPassenger,Rail 3.2.12,Postgresql

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

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但发生了同样的错误。

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

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

任何建议? 谢谢

我从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' }