honeybadger-io / heya

Heya 👋 is a campaign mailer for Rails. Think of it like ActionMailer, but for timed email sequences. It can also perform other actions like sending a text message.
https://www.heya.email
Other
736 stars 33 forks source link

Best practice for dealing with email address confirmation? #279

Open marckohlbrugge opened 1 day ago

marckohlbrugge commented 1 day ago

The example code shows this:

after_create_commit do
  OnboardingCampaign.add(self)
end

Which conveniently omits the fact that we'll want to hold off sending emails until the user has confirmed their email address.

The intuitive solution is to add a segment check to the campaign like below, but I believe this won't work as expected. The campaign will be triggered, the user does not fit the segment yet, and thus the campaign will never be sent. Even after email confirmation.

class OnboardingCampaign < ApplicationCampaign
  segment :confirmed?
end

The proper solution then seems to be to hold off on adding the user to the campaign, until the user has confirmed their email address. We could add OnboardingCampaign.add(user) in a ConfirmationsController.

This seems like a pragmatic solution, but it doesn't work well if you also use OAuth logins where email confirmations can be skipped. Which means we'll need to add another OnboardingCampaign.add(user) somewhere in the OAuth signup process.

So my question is this: what's the best practice for holding off on sending campaigns until the user has confirmed their email address?