Artem Garbin
Artem Garbin

Reputation: 93

Sending emails by schedule

I need to send mail on a schedule specified by the admin. Admin can specify two days in which is sending mail. The days which are specified through the admin interface, it days before the termination of activity of the company.

I would use DelayedJob for this.

class Email < ActiveRecord::Base
  belongs_to :campaign

end

class CreateEmails < ActiveRecord::Migration
  def change
    create_table :emails do |t|
      t.integer :days1
      t.integer :days2

      t.timestamps
    end
  end
end

class Campaign < ActiveRecord::Base
  has_many :emails

  def end_time
    created_at + ends_at.day
  end
end

Method end_time determines when you are finished with the activity of the company.

ends_at this field from the database to fill the admin at creation of the company.

Upvotes: 0

Views: 97

Answers (1)

Babar
Babar

Reputation: 1202

As an alternative you can create a rake task to call your method that sends the email, and there is this nifty little gem called Whenver, that can be used to set your cron for the automation of the process

Upvotes: 3

Related Questions