2013-02-26 49 views
3

根據我在這裏發佈的問題:mailer error in production only我決定創建一個小型腳手架應用程序來尋找解決方案。rails3不能在生產模式下發送smtp電子郵件

問題: 我不能發送(通訊)電子郵件與生產中的smtp,但它在開發中完美的作品。

你可以在my github repository找到該應用程序。

我剛剛創建了一個contact_messages腳手架和一個簡單的郵件程序。

點擊提交按鈕收到電子郵件後,錯誤日誌:

Started POST "/contact_messages" for 194.XXX.XX.XXX at 2013-02-26 19:43:59 +0000 
Processing by ContactMessagesController#create as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"xx0nxxJ2xwxxJavvZ278EUy2TABjD9CixxNcxDqwg=", 
"contact_message"=>{"name"=>"test", "email"=>"[email protected]", "message"=>"test1"}, "commit"=>"Create Contact message"} 
Rendered contact_mailer/confirmation.text.erb (0.3ms) 

Sent mail to [email protected] (38ms) 
Completed 500 Internal Server Error in 100ms 

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

的電子郵件得到保存,它們被列在索引中。所以數據庫應該可以正常工作。

我使用Ubuntu 12.04,Apache,Phusion Passenger,SMTP和Gmail帳戶。 這可能是一個服務器問題,或者我在應用程序中做錯了什麼?

我正在使用fail2ban和denyhost。這些工具可以阻止smtp?

任何幫助將不勝感激,謝謝!

+3

錯誤似乎表明它無法連接到SMTP服務器。您可以在端口25,26,465,587或者Gmail使用的端口上打開telnet到SMTP域,以瞭解您如何連接?如果沒有,請檢查您的防火牆,並確保您允許該端口的出站TCP連接。 – 2013-02-26 21:58:20

+0

感謝您的回答。但telnet連接到SMTP服務器工作... – crispychicken 2013-02-26 22:17:33

回答

0

我解決我的問題有變化,從山魈新passwort(API密鑰)。還是不知道問題是什麼,因爲與舊的它的發展模式,工作...

工作設置:

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

默認情況下,Rails通過連接到目標SMTP服務器來發送電子郵件。嘗試使用sendmail代替。在你的配置/初始化/ production.rb補充一點:

config.action_mailer.delivery_method = :sendmail 
+0

謝謝,我已經解決了這個問題。 – crispychicken 2013-02-27 18:14:23