Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails actionmailer, send mail at a specific time

I have a rails app with actionmailer that sends reminders to customers. So I want to have emails sent at specific datetimes. How can I do that, or any action from the controller?

like image 216
Suavocado Avatar asked Aug 31 '15 15:08

Suavocado


1 Answers

You can achieve this goal by using some kind of background tasks like resque or delayed_job for example.

Also, gems like whenever (Cron jobs in Ruby) would help you get there!

Take a look at this tutorial which shows sending emails with a Background Processor through Active Job and delayed_job

Update

To send emails at specific date time, you could use deliver_later with the wait_until option.

Notifier.welcome(User.first).deliver_later(wait_until: 10.hours.from_now)
like image 95
K M Rakibul Islam Avatar answered Nov 14 '22 23:11

K M Rakibul Islam