How to send emails later in Rails 5

July 2019

If you want to schedule an email to send after a certain period of time in Rails 5 – for instance, to send a welcome email the day after a user has created their account – you can use ActionMailer’s deliver_later method and add a wait_until parameter.

def create
  # ...

  UserMailer.welcome.deliver_later(wait_until: 1.day.from_now)

  # ...
end

There are a number of things you can do with this. Some ideas:

  • send the user an email when their trial is expiring
  • email the user if they haven’t completed the setup process
  • send the user a followup survey several weeks after they registered
  • send the user instructions if they got stuck on a certain part of your product

Don’t abuse this too much – only send email that’s truly important.