1

我是 Rails 的新手,我有一些问题。我使用 Devise 插件设置简单的应用程序,通过 Capistrano 将其部署在生产服务器(Linode 上的 Ubuntu,nginx + 乘客)上。现在尝试发送电子邮件(密码恢复、电子邮件确认等来自 Devise)。

但它不起作用。

我在 /enviroments/production.rb 中有这些行

  config.action_mailer.default_url_options = { :host => "myhostname.com" }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true

当我尝试从我的应用程序发送电子邮件时,我收到 500 错误“我们很抱歉,但出了点问题。”(乘客)。在日志/production.log

Net::SMTPServerBusy (451 4.3.0 Temporary system failure. Please try again later.)

我使用 exim4 作为邮件服务器。我也尝试安装 sendmail 并更改

config.action_mailer.delivery_method = :sendmail

电子邮件开始发送,但应用程序运行缓慢。

所以,我的问题是:我需要做什么来解决我的问题,我可以在哪里阅读完整的手册或文档来配置 exim4 以使用 rails 应用程序?

谢谢。

4

2 回答 2

3

According to chapters 5 and 5.1 of ActionMailer official doc : http://guides.rubyonrails.org/action_mailer_basics.html

We can see that there are no ':exim4' option available as 'delivery_method'.

So I would suggest to "cheat" ActionMailer that he is using sendmail (though he will use exim4). Use the following configuration in your config/enviroments/production.rb file :

config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
  :location => '/usr/sbin/exim4',
  :arguments => '-i'
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

Arguments match the following exim4 options :

  • -t option causes the recipients of the message to be obtained from the To:, Cc:, and Bcc: header lines in the message instead of from the command arguments.
  • -i option prevents a line containing just a dot from terminating the message. Only an end-of-file does so.

Don't use the -t option.

In order to configure properly your Exim4 deamon, I suggest this quick how-to : http://noosfero.org/Development/MailSending

I highly recommend you choose "smarthost" on the first screen instead of "Internet site".

This is because mail providers of the Internet (gmail, yahoo, etc...) do block any e-mails that come from an unkown IP adresses on Internet by default (this include your new server IP adress of course).

If you choose 'smarthost' your server will have to connect to an existing (and trusted) mail server (gmail, yahoo, etc...) in order to forward its own e-mail messages. This will ensure your e-mails get their ways up to their destination.

=== UPDATE

I had problem making it working with -t optin since some version of rails (3.2). I had the following error in my /var/www/my_app/log/production.log :

Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25)

So I removed the -t option as rails was not including anymore the To: field in the message and rather sent it in the command line.

I found some other developper having a similar issue on this app : gitlabhq

I hope this help people to make rails working with exim4.

于 2012-10-10T08:50:06.357 回答
0

Debian 8 + Rails4.2.6 + Exim 版本 4.84_2

我添加到我的config/enviroments/production.rb文件中:

config.action_mailer.default_options     = { from: 'mybox@hostname.com' }
config.action_mailer.default_url_options = { host: 'hostname.com' }
config.action_mailer.perform_deliveries    = true
config.action_mailer.raise_delivery_errors = true

并从delivery_methodsendmail_settings参数中清除(注释) :

# config.action_mailer.delivery_method = :sendmail
# config.action_mailer.sendmail_settings = {
#     :location => '/usr/sbin/exim4',
#     :arguments => '-i'
# }

这是工作!

对我来说,道格拉斯的回答没有用。

于 2016-12-01T16:29:38.203 回答