使用cron选项卡发送邮件时连接拒绝 [英] Connection refuse when sending mail with cron tab

查看:273
本文介绍了使用cron选项卡发送邮件时连接拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当 gem使用时,我都会每天发送电子邮件任务。
我在RAKEFILE名字咖啡中创建了一个rake任务。这是我的任务代码:

I'm doing a daily sending email task by using whenever gem. I created a rake task in RAKEFILE name coffee. Here is my task's code:

task :coffee => :environment  do
  ReservationBooksNotify.notify.deliver
  puts "hihi"
end

当我在控制台
rake coffee 中运行此任务时,它工作正常!
但是当我在schedule.rb中创建一个每分钟自动发送邮件的时间表时,我收到一个错误消息


When I run this task in console rake coffee, it worked! But when I create a schedule in schedule.rb to automatically sending mail every minute, I get an error


hihi
耙子中止了!
连接被拒绝 - connect(2)

hihi rake aborted! Connection refused - connect(2)

我跟踪时的错误

The error when I trace

rake coffee RAILS_ENV=production --trace
** Invoke coffee (first_time)
** Invoke environment (first_time)
** Invoke rails_admin:disable_initializer (first_time)
** Execute rails_admin:disable_initializer
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
** Execute environment
** Execute coffee
rake aborted!
Connection refused - connect(2)
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:540:in `initialize'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:540:in `open'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:540:in `tcp_socket'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:549:in `block in do_start'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:549:in `do_start'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:519:in `start'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:144:in `deliver!'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:2034:in `do_delivery'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:229:in `block in deliver'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:415:in `block in deliver_mail'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `block in instrument'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `instrument'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:413:in `deliver_mail'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:229:in `deliver'
/home/duykhoa12t/Working/Bbookproject/Code/bbook/Rakefile:10:in `block in <top (required)>'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => coffee

我的schedule.rb(在/ config)

My schedule.rb (in /config)

set :output, "~/Working/whenever.log"

every 2.minutes do
  rake 'coffee'
end

我认为我的邮件配置没有问题,因为它在我发送邮件的控制器和安慰。请帮助我,谢谢!

I think my mailer configure has no problem because It worked when I send mail in controller and in console. Please help me, thanks!

推荐答案

最后,我不知道为什么,我尝试 rake assets :预编译,然后重启服务器,一切正常!

Finally, I don't know why, I try rake assets: precompile, then restart server, everything works!

这篇关于使用cron选项卡发送邮件时连接拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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