Ask A Question


You’re not receiving notifications from this thread.

Send an Email On a Date Specified in a Database Column

Liz Bayardelle asked in Rails

I have what I think is a working setup to send emails via Delayed_Job. However, I haven't received my test email and it isn't practical to wait for more to happen with a delay of days. I need to figure out:

  1. What's wrong that's causing the email not to send.
  2. How to test it without waiting days at a time.

I'm new to Delayed_Job, so pardon the newbie mistakes.

Here's the model that includes the send_reminder_emails method. They were fully functional without the delay bit, so at least I know that much works:

class Reminder < ActiveRecord::Base
  belongs_to :user
  before_save :create_mail_date
  after_save :send_reminder_emails
  extend FriendlyId
  friendly_id :name, use: [:slugged, :finders]

  def create_mail_date
    @schedule =
    case self.repeating
    when "Weekly"
    when "Monthly"
    when "Yearly"
    if self.repeating = @schedule.next_occurrence(
    self.mail_date = - 7.days


  def send_reminder_emails
      if self.reminder
            RemainderMailerJob.set(wait_until: self.mail_date).perform_later(user, remainder)  ##this line is the issue
            #ReminderMailer.delay(run_at: self.mail_date).reminder_send(self.user, self)ow
         self.create_mail_date   ##this is another solution I've tried
  handle_asynchronously :send_reminder_emails


The references to schedule are via the Ice_Cube gem and all of the date stuff has been tested via my console and is working. Here is my reminder_mailer.rb:

class ReminderMailer < ApplicationMailer
  default from: ""

  def reminder_send(user, reminder)
    @user = user
    @reminder = reminder

    mail(to:, subject: "Reminder! #{} is fast approaching!")

I installed Delayed_Job step by step from their readme for Rails 4. Any help getting the delayed part of this mailer ironed out is appreciated!


Hi Liz,

Scheduling can be kind of difficult to get a handle on.

Are you running the daemon on your development environment? (The script that manages/runs delayed_jobs in the background.) This will essentially create a worker process to queue up your jobs and process them, if I'm not mistaken. I haven't worked directly with delayed_job, but it's similar to Resque and Sidekiq.

You should also be able to queue a job for a few seconds in the future from the command line for testing purposes. :)

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.