当Rails Mailer发送电子邮件时,导致文件结束错误的原因是什么?

All*_*ton 7 email ruby-on-rails actionmailer

使用gmail帐户开发的Rails 3.2.8应用程序作为"发送地址".邮件发送工作时我的environment.rb文件包含:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
   :address => "smtp.gmail.com",       
   :port =>  587,                         
   :domain => "gmail.com",              
   :authentication => :login,            
   :user_name => "accountname",         
   :password => "123456789"              
}
Run Code Online (Sandbox Code Playgroud)

我在我的应用程序日志中收到此消息:EOFError(到达文件末尾):当上面的代码更改为如下所示:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
   :address => "mail.company.com",
   :port =>   25,   
   :domain => "company.com", 
   :authentication =>   :login,
   :user_name =>  "accountname", 
   :password => "123456789"
}
Run Code Online (Sandbox Code Playgroud)

我可以告诉您,我可以向电子邮件地址发送手动电子邮件,并在使用ThunderBird等电子邮件客户端时看到它,因此我知道accountname@company.com正常运行.

我不明白文件结束错误是如何发挥作用的.我也无法弄清楚如何获得更多信息出现在日志中.

我期待着阅读一些确定文件结束原因的建议.

Started POST "/sendInvites?locale=en&lot_id=18&user_id=17" for 99.99.99.99 at 2013-10-03 08:52:09 -0700
Processing by WaitingListsController#sendInvites as HTML
  Parameters: {"authenticity_token"=>"uwz/6pW1rLPXR4gU3m3OwCmU0O3DSJ/haNM2/ai+OR8=", "locale"=>"en", "lot_id"=>"18", "user_id"=>"17"}
=======>>>> Beginning Send Invitation Process <<<<=======
=======>>>> just before the  PassEmailer.requestApprovedWL IS called to send the invitation <<<<=======
>>>> Beginning ::: requestApprovedWL(user_info) <<<<=======
  Rendered pass_emailer/requestApprovedWL.erb (0.9ms)
>>>> at the end of ::: requestApprovedWL(user_info) <<<<=======
Completed 500 Internal Server Error in 1718ms

EOFError (end of file reached):
  app/controllers/waiting_lists_controller.rb:276:in `sendInvites'
Run Code Online (Sandbox Code Playgroud)

ear*_*son 1

对于仍然遇到此问题的任何人,“每当”似乎默认为“生产”。它在开发或登台过程中使用您的生产变量(或寻找它们)。另外,根据文档,它不会加载 Rails 环境。

当您处于开发或登台阶段时,您必须手动让 Schedule.rb 知道这一点。在此处找到 File.expand_path 方法后,以下是我启动 Schedule.rb 文件的方法:

require File.expand_path(File.dirname(__FILE__) + "/environment")
set :environment, Rails.env 
set :output, Rails.root.join('log','cron.log')
Run Code Online (Sandbox Code Playgroud)

这为您提供了 Rails 环境,并允许您设置日志记录路径。