# Sending mail (ActionMailer) after a delay

**URL:** <https://www.ruby-forum.com/t/sending-mail-actionmailer-after-a-delay/88563>\
**Category:** Rails\
**Created:** [March 12, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/sending-mail-actionmailer-after-a-delay/88563 "2007-03-12T17:55:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![akapal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@akapal](https://www.ruby-forum.com/u/akapal)\
**Post date:** [March 12, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/sending-mail-actionmailer-after-a-delay/88563/1 "2007-03-12T17:55:26Z")

</div>

Hi,

I’d like my app to be able to send an email off at a predetermined time  
after a given contoller action occurs.

Oh, and I’d like to be able to change this time on the fly (ie, reset  
the timer) if the controller action is called again before the original  
time is reached.

Does anyone know of a good way to do this?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![akapal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@akapal](https://www.ruby-forum.com/u/akapal)\
**Post date:** [March 12, 2007, 6:46pm UTC](https://www.ruby-forum.com/t/sending-mail-actionmailer-after-a-delay/88563/2 "2007-03-12T18:46:18Z")

</div>

Have a look at BackgrounDrb. Essentially you’d do something like  
send\_me\_later = DeferredMail.new(:send\_after=\>2.hours.from\_now), then  
a BackgrounDrb worker would scan the table every minute and send mail  
as needed. The controller could always destroy the DeferredMail object  
before it was sent, if you needed to cancel the operation.

Gwyn.  
[http://gwyn.dezyne.net/](http://gwyn.dezyne.net/)

---

<div class="post-metadata">

**Author:** ![akapal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@akapal](https://www.ruby-forum.com/u/akapal)\
**Post date:** [March 13, 2007, 3:39am UTC](https://www.ruby-forum.com/t/sending-mail-actionmailer-after-a-delay/88563/3 "2007-03-13T03:39:47Z")

</div>

Thanks Gwyn. I’ll give that a shot.
