Send email depending on the date

2

I'm doing a small agenda in Ruby on Rails, I currently use UserMailer to send emails, but I can not find the way to send mail according to the date of my created event.

For example, if I create an event in my calendar today for 3 days, I would like you to send me an email the day the event starts.

Will anyone know how to make the conditionals work on date?

    
asked by Angel Ac 19.09.2016 в 17:52
source

3 answers

0

You can use the deliver_later method of the class ActionMailer :: MessageDelivery

For example you have in /mailers/user_mailer.rb

class UserMailer < ApplicationMailer
  def welcome(user)
   ...
  end
end

When you call the welcome method you can indicate a delay, for example in this 3 day case

UserMailer.welcome(User.first).deliver_later(wait: 3.day)

More information at api

    
answered by 24.09.2016 в 06:14
0

You could use a cronjob with the gem whenever I could check every day if you have an email to send, saving when you have to send the emails in a table and the job check if there is an email to send each day.

    
answered by 11.10.2016 в 18:36
0

I recommend you use sidekiq to manage your processes in background mode, so you avoid that in your process of sending emails you lose one (among other features). This can be used with sidetiq which allows you to schedule your work. For more information.

Greetings.

    
answered by 11.10.2016 в 19:07