Sending a series of delayed emails for user onboarding

I need to send a series of emails to new user signups as part of our onboarding process.

Since I’m already using Delayed Job for other tasks in the app I initially thought of firing a bunch of delayed calls to my mailer with the run_at param set to the required time periods but this looks quite odd to me in the User controller (example):

def create
  @user = User.new(params[:user])

  MyMailer.delay(run_at: 1.day.from_now).send_email('one', @user)
  MyMailer.delay(run_at: 2.days.from_now).send_email('two', @user)
  MyMailer.delay(run_at: 5.days.from_now).send_email('three', @user)
  MyMailer.delay(run_at: 10.days.from_now).send_email('four', @user)

  if @user.save
    redirect_to dashboard_path
  else
    render action: "new"
  end
end

I realize I could extract the mailer calls out to a new method or use a service object but I’m more concerned about this being a reasonable way to queue emails for timed delivery. Is anyone here using this method?

[Bonus Question!] If this does seem like a good method then how would I cancel outstanding emails if I needed to? A new user could cancel their account during the first 10 days and since the delayed jobs exist as independent Active Record objects they wouldn’t automatically be deleted when a User account is destroyed. I wouldn’t want to annoy cancelled users by sending them the remainder of their onboarding emails.

I should also add that I’m using Mandrill’s API to send app emails.

They do have a scheduled email service but not only is it a separately charged featured but future emails would be ‘stored’ outside my app/database which makes me a little uncomfortable since I’d have to hit their API every time I wanted to change or delete any scheduled emails.

I’d like to keep it all inside my app if possible.

Hi @weavermedia,

I strongly recommend you use http://intercom.io for this, instead of building it yourself.

This is what we use on Upcase, our other products, and many client projects.

Unlike Mailchimp’s projects, you don’t hit an API in order to specifically send the messages. You set up the messages that will be sent based on certain criteria (time, cancelation, or other events in your system) and you send those events to intercom.

It is overall much, much better than building the functionality yourself.

2 Likes

Thanks @cpytel, I’ll look into it. I already use Intercom for casually tracking user sign-ins but I have concerns about using it for this.

As a developer it looks great because of the easy integration and proven track record. However as a company I wouldn’t want to give up my branding in place of those (almost) plain text Intercom emails, and as a customer I always feel like part of my app experience has been outsourced to a third-party when I see those generic Intercom emails arrive in my inbox (no offence).

I’ll dive into the Intercom docs and talk to my client about it, see if we can integrate in a way that satisfies everybody.

Thanks again.

@weavermedia, Intercom actually has custom email templates which allows you to completely edit the HTML of the email: Create custom email templates | Help Center

@cpytel That’s excellent. We did go with Intercom in the end, thanks for the push!

Their service wraps up a few other things nicely into one package. I’m looking forward to getting stuck in.