Caley Woods
Caley Woods

Reputation: 4737

Rails send email on schedule

I have an app that presents a calendar allowing you to create events that display on the calendar. One of the fields you set is the day the event starts. I would like to be able to send email reminders out when the day of the event arrives.

I'm new to rails so I'm not exactly sure what I need or where to start. I read the rails guide for ActionMailer and generated a mailer, I was assuming I would need one of those. I also read the rails guide for observers and thought maybe that might be a route to what I want to accomplish.

Let's say every day, 7 days a week at 9am central, a job (cron or rake task) should run that searches the 'start_at' column of every Event in the database (sqlite locally, Postegre with heroku in production) and if the start_date is equal to 'today?' then send the action mailer template to remind the user.

So what's the best way to (and with what tool) to build a job to examine that database and kick off emails every day? In the future I guess this would grow to reminders ahead of time.

Some pseudo-code:

def send_email
  if self.start_at == Date.today #assuming self.start_at.today? works too.
    // send email
end

Just not sure how to get that working.

Upvotes: 0

Views: 2052

Answers (1)

Chris Kooken
Chris Kooken

Reputation: 33870

You could have a Controller/Action that does it, then call the url from a cron job on a specified schedule using a command like cURL.

Upvotes: 2

Related Questions