You can use Active Job to send emails by scheduling a task at a specific time.
An active task is the basis for the announcement of tasks and their launch on various queue servers. These tasks can be everything from regularly scheduled fees, to billing, to mailing lists. All that can be cut into small units of work and work in parallel, really.
To start and execute tasks in production, you need to configure the server queue, that is, you need to decide for any third queue of the queue library that Rails should use. The rails themselves provide only a processing system in the process that only saves jobs in RAM. If the process failed, or the machine is reset, then all outstanding tasks will be lost using the built-in default async. This may be good for small applications or non-critical tasks, but most production applications will need to choose a permanent backend.
The active job has built-in adapters for several queue servers (Sidekiq, Resque, Delayed Job, and others). For an updated list of adapters, see API Documentation for ActiveJob :: QueueAdapters.
After setting up the queue adapters, create a Job to send emails
class RemainderMailerJob < ApplicationJob queue_as :default def perform(user, remainder) ReminderMailer.reminder_send(user, reminder).deliver end end
To send mail at a specific time, you need to queue a task and run it at a specific time. If you need to send mail in 7 days, then name this piece of code where you need it.
RemainderMailerJob.set(wait: 1.week).perform_later(user, remainder)
Now this task will be completed in 1 week, which in turn calls the mail program at that time, so your letters will be sent on a certain day.
IF you know a specific time by date, you can use
RemainderMailerJob.set(wait_untill: <Specific date>).perform_later(user, remainder)
If you have any doubts about active work, kindly refer to Active Work Basics