Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 746563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:06:19+00:00 2026-05-14T14:06:19+00:00

I would like to be able to send a string of emails at a

  • 0

I would like to be able to send a string of emails at a determined interval to different recipients.

I assign to each Contact this series of Emails called a Campaign, where Campaign has Email1, Email2, etc. Each Contact has a Contact.start_date. Each Email has email.days which stores the number of days since a Contact’s start-date to send the email.

For example: Email1.days=5, Email2.days=7, Email3.days=11

Contact1.start_date = 4/10/2010; contact2.start_date = 4/08/2010

IF today is 4/15, then Contact1 receives Email 1 (4/15-4/10 = 5 days)
IF today is 4/15, then Contact2 received Email 2 (4/15 – 4/8 = 7 days).

What’s a good action to run every day using a cron job that would then follow these rules to send out emails using ActionMailer?

NOTE: The question isn’t about using ActionMailer. It is about doing the "math" as well as the execution. Which email to send to whom? I am guessing it has to do with some version of Date – Contact[x].start_date and then compare against email[x].days but I’m not exactly clear how. Thanks.

I’d like guidance on whether to use date.today versus time.now as well.

Note: the intent is that an individual person may need to schedule individual follow-up on a consistent basis. Rather than having to remember when to follow up which email with whom, it would just follow a pre-determined campaign and send for that person.

So it’s not a "bulk mail" — it’s really automating the follow-up for individual correspondence.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:06:19+00:00Added an answer on May 14, 2026 at 2:06 pm

    I would use DelayedJob for this ( assuming you are not sending large number of emails emails a day, i.e. 100’s of thousands per day etc.)

    class Email < ActiveRecord::Base
      belongs_to :campaign
      after_create :schedule_email_dispatch
    
      def schedule_email_dispatch
        send_at(campaign.created_at + self.days.days, :send_email)
      end
    
      def send_email
      end
    end
    

    Run the workers using the rake task:

    rake jobs:work
    

    Every time a new Email object is created a delayed job item is added to the queue. At the correct interval the email will be sent by the worker.

    @campaign = Compaign.new(...)
    @campaign.emails.build(:days => 1)
    @campaign.emails.build(:days => 2)
    @campaign.save # now the delay
    

    In the example above, two delayed job entries will be created after saving the campaign. They are executed 1 and 2 days after the creation date of the campaign.

    This solution ensures emails are sent approximately around the expected schedule times. In a cron job based solution, disptaching happens at the cron intervals. There can be several hours delay between the intended dispatch time and the actual dispatch time.

    If you want to use the cron approach do the following:

    class Email < ActiveRecord::Base
      def self.dispatch_emails
        # find the emails due for dispatch
        Email.all(:conditions => ["created_at <= DATE_SUB(?, INTERVAL days DAY)", 
                 Time.now]).each do |email|
          email.send_email
        end
      end
    end
    

    In this solution, most of the processing is done by the DB.

    Add email.rake file in lib/tasks directory:

    task :dispatch_emails => :environment do
      Email.dispatch_emails
    end
    

    Configure the cron to execute rake dispatch_emails at regular intervals( in your case < 24 hours)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my two applications to be able to send strings to each
I would like to be able to render a view and send it as
Would like to be able to set colors of headings and such, different font
I would like to be able to send the contents of a merged word
I would like to be able to loop through all of the defined parameters
We would like to be able to nightly make a copy/backup/snapshot of a production
I would like to be able to use the Tab key within a text
I would like to be able to display some dynamic text at the mouse
I would like to be able to obtain all the parameter values from the
I would like to be able to define and use a custom type in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.