[英]mailer error in production only
設置: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
對於郵件,我將smtp與山man或gmail一起使用。 Gmail設置可以在另一個應用程序中正常運行...
我的環境
# 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
更新:我發現提交保存在我的索引中。 所以我想數據庫可以工作。
有什么建議嗎? 謝謝
我通過從山rill改成新的密碼(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'
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.