仅在生产中出现邮件错误 [英] mailer error in production only

查看:41
本文介绍了仅在生产中出现邮件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Setup: VPS with Ubuntu 12.04, Apache, PhusionPassenger, Rail 3.2.12, Postgresql

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

I want to send a confirmation mail with my app. In development mode everything works fine, the user receives a mail but in production I get this error (log):

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 行被标记):

So I guess, error should be in newsletters_controller.rb (line 45 is marked):

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

NewsletterMailer.rb

class NewsletterMailer < ActionMailer::Base
  default from: "some@email.com"

  def confirmation(email)
    mail to: email,
         subject: "Welcome"
  end
end

同样,它只适用于开发,不适用于生产.我也尝试将数据库更改为Mysql2,但出现同样的错误.

Again, it works only in development but not in production. I also tried to change the database to Mysql2 but the same error occurs.

我的数据库.yml:

production:
  adapter: postgresql
  encoding: unicode
  reconnect: false
  database: app_production
  pool: 5
  username: user
  password: secret
  host: localhost

对于邮寄,我使用带有 mandrill 或 gmail 的 smtp.Gmail 设置在其他应用中运行良好...

For mailing I use smtp with mandrill or gmail. Gmail-Settings work well in another app...

我的环境.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

更新:我发现提交被保存在我的索引中.所以我猜数据库是有效的.

UPDATE: I found out that the submits get saved in my index. So I guess the DB works.

有什么建议吗?谢谢

推荐答案

我通过更改 mandrill 的新密码 (api-key) 解决了我的问题.仍然不知道问题出在哪里,因为旧的它在开发模式下工作......

I solved my problem with a change to a new passwort (api-key) from mandrill. Still don't know what the problem was, because with the old one it worked in development mode...

工作设置:

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

这篇关于仅在生产中出现邮件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆