Automated Follow-Up Emails

Programming

If your email service provider (ESP) has an API and you have a PHP/MySQL server, you can send automated follow-up emails!

But before we jump in: why would you want to send a follow-up email automatically? There are tons of applications for this! Let’s suppose you get someone to sign up off of your website and you want that user to take some action (for example, confirming their subscription or completing a purchase). Or let’s suppose you’re running a start-up and you’re finally ready to start your beta program but many of the people who signed up months ago aren’t responding now.

The first email didn’t do the trick; the user didn’t respond. But considering that the user has already expressed some interest in receiving that first email, maybe they just need a nudge. But we have to be careful: we don’t want to annoy potential clients and we don’t want to accidentally nudge users who have already responded.

Essentially, we need some way to check whether or not each user has responded to the first email before sending a second one. However, many email service providers don’t have a built-in feature for sending automated follow-up emails. And sometimes ESPs do provide this capability, but you need to query a database that is separate from your ESP’s database to check whether or not a follow-up is necessary. For example, if you need to check whether or not a user has completed a purchase, you may need to query your company’s sales database. Higher-end ESPs such as ExactTarget provide this capability, but many others do not. But that’s okay — we can build this functionality ourselves!

To start, let’s record the send of the first triggered email. For this, we can use a simple MySQL database. All we want to keep track of is the timestamp of the first send and the email address it went to. In other words, for each send of the first email, we should add a row to our database. That way, in one day from now (or two days, or a week, or whatever timeframe you want) you can check to see if you should be following up with this user.

(A word of caution here: be sure not to save your users’ email addresses in plain text. You definitely want to encrypt these addresses because you don’t want to let evil spammers get ahold of your precious list. In fact, it would be best if your database weren’t publicly accessible at all.)

Next, we should set up a cron job to check the database every so often. This is where the hard work takes place: checking whether to send the follow-up email. For each entry in the database with a timestamp in the specified range (ex: more than 24 hours ago), we want to check whether to send that user a follow-up email. Depending on what type of action you’re following-up on, you may want to check different things. In some circumstances, it may make sense to simply check whether the user clicked through. In other circumstances, you may want to check whether the user actually completed a purchase. Once you determine that you want to send this user a follow-up email, it’s simple to post the API command to your ESP. Regardless of whether or not you decided to send the follow-up email, you can now delete this row from the database.

How often should this cron job run? Well, it depends on what you’re trying to do. If you want to send all of your automated follow-ups at, for example, 8AM the morning after you sent the first email, you only need to run this cron job at 8AM every morning. But if you want to send the follow-up about 24 hours after the first, you should run the cron job more frequently.

In summary, given only a rudimentary API, we can still complete complex emailing tasks by programming these capabilities ourselves. This idea can also be extended to handle other tasks, such as A/B split tests for trigger emails. If you’re feeling constrained by the capabilities of your ESP, although it’s worth considering switching to a more powerful platform, sometimes it’s possible to solve your own problems!