我需要每周发送一些电子邮件。 我安装了邮件并做了几次测试。工作正常。
但我无法使用Whenever自动发送电子邮件。 在各种论坛中搜索过但仍无法修复。
型号/ HrCurriculumIntern
def self.send_reply_interns
@users = HrCurriculumIntern.where(:answer_sent => t('labels.n'))
InternMailer.send_reply_interns(@users).deliver
end
邮件程序/ InternMailer
default :from => "username.mailer@gmail.com"
def send_reply_interns(users)
@users = users
mail(:to => "<lorenadgb@gmail.com>", :subject => t('subjects.send_reply_interns'), :from => "username.mailer@gmail.com")
end
CONFIG / schedule.rb
set :environment, :development
every 2.minutes do
runner "HrCurriculumInterns.send_reply_interns"
end
我按照以下步骤操作: Eu segui estes passos:
随时。
每当
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /var/www/form/3216/email/trunk && script/rails runner -e development '\''HrCurriculumInterns.send_reply_interns'\'''
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.
每当-update-crontab
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /var/www/form/3216/email/trunk && script/rails runner -e development '\''HrCurriculumInterns.send_reply_interns'\'''
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.
我看不出问题,有什么建议吗?
答案 0 :(得分:1)
使用快捷方式“when -w”编写crontab。看起来你使用“when -update-crontab”而不是“when -update-crontab”。因此,您的命令都没有实际编写crontab文件。答案应该是
[write] crontab file updated
之后使用“crontab -l”来验证是否写入了正确的cron。
答案 1 :(得分:0)
我找到了解决方案。
我的代码错了。我做了一些改动:
邮件程序/ intern_mailer.rb
def send_reply_interns
@users = HrCurriculumIntern.where(:answer_sent => t('labels.n'))
mail(:to => "<lorenadgb@gmail.com>", :subject => t('subjects.send_reply_interns'), :from => "username.mailer@gmail.com")
end
模型/ hr_curriculum_intern.rb
def self.send_reply_interns
InternMailer.send_reply_interns.deliver
end
schedule.rb
set :environment, :development
every 2.minutes do
runner "HrCurriculumIntern.send_reply_interns"
end
现在的作品是\ o /
感谢您的回复