1

設置:VPS與Ubuntu 12.04,阿帕奇,PhusionPassenger,鐵路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"=>"[email protected]"}, "commit"=>"Submit"} 

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

Sent mail to [email protected] (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: "[email protected]" 

    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 

如需郵寄我使用SMTP山魈或Gmail。 Gmail中的設置在其他應用程序很好地工作......

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

更新: 我發現該得到的提交保存在我的索引。所以我猜數據庫工作。

有什麼建議嗎?謝謝

+0

你能真正連接到生產中的數據庫?如果您嘗試在控制檯中手動創建「通訊」,會發生什麼情況? – 2013-02-26 15:41:38

+0

如果我提交,電子郵件會保存在我的數據庫中,我會在索引中看到它們。所以我想這與數據庫有關聯... – crispychicken 2013-02-26 16:13:26

+0

是的,這表明問題在於郵件設置。你可以添加這些。 – 2013-02-26 16:15:24

回答

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