Send ActionMailer from external ruby file?
i want to make a cronjob which execute a specific ruby file in the script dir开发者_Python百科ectory of my rails app. how can i achieve, that i can execute an actionmailer to use deliver? how do i get this mailer into this ruby file?
thanks!
Skipping the part about creating a task in crontab, here is what you can do:
- Create a rake task, in lib/tasks, which sends that email and invoke the rake task from your cron job. I have done this and this works, pretty well for me.
Load the Rails environment explicitly in your ruby script. I do this in some daemons. You can do something like this :
require File.dirname(__FILE__) + "/../config/application" Rails.application.require_environment!
Use the rails runner.
rails runner -h
will give you the necessary information
精彩评论