哪里可以阅读完整的手册来配置SMTP for Rails? [英] Where i can read complete manual to configure SMTP for Rails?

查看:143
本文介绍了哪里可以阅读完整的手册来配置SMTP for Rails?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails中的新手,我有一些问题。
我使用Devise插件设置简单的应用程序,通过Capistrano将其部署在生产服务器(Ubuntu on Linode,nginx + passenger)上。现在尝试从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错误我们很抱歉,但出了问题
(乘客)。
在log / production.log中

  Net :: SMTPServerBusy(451 4.3.0临时系统故障,请重试稍后。)

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

  config.action_mailer.delivery_method =:sendmail 

电子邮件开始发送,但应用程序工作如此缓慢。



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



谢谢。

解决方案

根据ActionMailer官方文档的第5章和第5.1章: http://guides.rubyonrails.org/action_mailer_basics.html



我们可以看到没有':exim4'选项可用作'delivery_method '。



所以我建议使用ActionMailer,他正在使用sendmail(虽然他会使用exim4)。
在config / enviroments / production.rb文件中使用以下配置:

  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

参数与以下exim4选项匹配:




  • -t选项原因消息的收件人将从消息中的收件人:,抄送:和密件抄送:标题行获取消息,而不是从命令参数中获取

  • i选项可防止仅包含点的行终止邮件。只有文件结尾才能这样做。



不要使用-t选项。



为了正确配置您的Exim4 deamon,我建议这个快速的方法: http:/ /noosfero.org/Development/MailSending



我强烈建议您在第一个屏幕上选择 smarthost ,而不是Internet网站。



这是因为互联网的邮件提供商(gmail,yahoo等)阻止来自未知IP地址的任何电子邮件默认情况下是互联网(这当然包括您的新服务器IP地址)。



如果您选择smarthost,您的服务器将必须连接到现有的(和受信任的)邮件服务器(gmail,yahoo等),以转发自己的电子邮件。
这将确保您的电子邮件达到目的地。



===更新



由于某些版本的rails(3.2),我有使用-t optin功能的问题。
我的 /var/www/my_app/log/production.log 中出现以下错误:

 code> Errno :: ECONNREFUSED(Connection denused  -  connect(2)forlocalhostport 25)

所以我删除了-t选项,因为rails不再包含消息中的To:字段,而是在命令行中发送。



我发现了一些其他开发人员在此应用程序中有类似的问题: gitlabhq



我希望这有助于人们使用exim4。


I newbie in Rails, and i have some question. I setup simple application with Devise plugin, deploy it on production server (Ubuntu on Linode, nginx + passenger) via Capistrano. And now try to send emails (password recovery, email confirmation and etc from Devise).

But it doesent work.

I have this lines in /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

And when i try to send email from my app, i get 500 error "We're sorry, but something went wrong. " (by Passenger). In log/production.log

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

I use exim4 as mail server. Also i try install sendmail and change

config.action_mailer.delivery_method = :sendmail

Emails start sends but application work so slow.

So, my question is: what i need to do with my problem and where i can read complete manual or documentation to configure exim4 for work with rails application?

Thanks.

解决方案

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.

这篇关于哪里可以阅读完整的手册来配置SMTP for Rails?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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