rails3不能在生产模式下发送smtp邮件

时间:2021-12-28 18:12:12

According to my problem I posted here: mailer error in production only I decided to create a small scaffold app to find a solution.

根据我在这里发布的问题:生产中的mailer错误,我决定创建一个小型的scaffold应用程序来寻找解决方案。

The problem: I can't send (newsletter)email with smtp in production, but it works perfectly in development.

问题:我不能在生产中发送smtp的电子邮件,但它在开发中非常有效。

You can find the app in my github repository.

你可以在我的github库中找到这个应用。

I just created a contact_messages scaffold and a simple mailer.

我刚刚创建了一个contact_message scaffold和一个简单的mailer。

The error log after clicking on the submit button to receive email:

点击提交按钮接收邮件后的错误日志:

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"=>"test@testemail.com", "message"=>"test1"}, "commit"=>"Create Contact message"}
Rendered contact_mailer/confirmation.text.erb (0.3ms)

Sent mail to test@testemail.com (38ms)
Completed 500 Internal Server Error in 100ms

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

The emails get saved, they are listed in the index. So the database should work fine.

这些邮件被保存,它们列在索引中。因此,数据库应该可以正常工作。

I'm using Ubuntu 12.04, Apache, Phusion Passenger, SMTP with Gmail Account. Could this probably be a server issue, or am I doing something wrong in the app?

我正在使用Ubuntu 12.04, Apache, Phusion Passenger, SMTP和Gmail帐户。这可能是服务器问题,还是我在应用中做错了什么?

I'm using fail2ban and denyhost. Could these tools block smtp?

我使用的是fail2ban和denyhost。这些工具能阻止smtp吗?

Any help will be appreciated, thanks!

如有任何帮助将不胜感激,谢谢!

2 个解决方案

#1


3  

By default, Rails sends email by connecting to the target SMTP server. Try using sendmail instead. Add this in your config/initializers/production.rb:

默认情况下,Rails通过连接目标SMTP服务器发送电子邮件。尝试使用sendmail代替。在配置/初始化器/产品中添加这个。

config.action_mailer.delivery_method = :sendmail

#2


0  

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...

我从mandrill更改了一个新的密码(api-key),从而解决了我的问题。仍然不知道问题是什么,因为旧的它在开发模式下工作…

The working setting:

工作环境:

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

#1


3  

By default, Rails sends email by connecting to the target SMTP server. Try using sendmail instead. Add this in your config/initializers/production.rb:

默认情况下,Rails通过连接目标SMTP服务器发送电子邮件。尝试使用sendmail代替。在配置/初始化器/产品中添加这个。

config.action_mailer.delivery_method = :sendmail

#2


0  

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...

我从mandrill更改了一个新的密码(api-key),从而解决了我的问题。仍然不知道问题是什么,因为旧的它在开发模式下工作…

The working setting:

工作环境:

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