Remember to Floss With an Interactive Reminder Email


Posted on

flossedtodayIt’s been over a month since New Year’s Day, but I’m still trying to keep some of my New Year’s resolutions. I’ve found the best way to keep them is to have someone remind you—nag you, really.

Likely, your friends don’t want to spend their free moments nagging you though. So, let’s have SendGrid do it instead.

Resolve to Be a Flosser

You’re likely familiar with sending email through SendGrid, but we can also receive it via the Inbound Parse Webhook. We can combine the two to act like a person reminding us of our New Year’s resolution.

How? We’ll send an email each day asking if we did our New Year’s resolution. If we reply “yes,” the app will stop sending reminders that day. If we don’t reply, it will send us another reminder later in the day. Essentially, this will nag us until we say “Yes.” I like this concept. It’s a friendly nag.

I’ve built an example of this that you can use. It’s called Flossed Today and it reminds me to floss. You can use the existing hosted version or deploy it to your own server with the code on GitHub.

How Does It Work?

There is a background task that delivers the reminder email. The gist of that code looks like this:

Reminder.send = function(to, fn) {
  var payload = {
    to: to,
    replyto: c.REPLYTO,
    from: c.FROM,
    subject: c.SUBJECT,
    text: c.BODY
  }

  sendgrid.send(payload, function(err, json) {
    if (err) {
      fn(err, null);
    } else {
      fn(null, json);
    };
  });
};

Then the app needs a way to capture replies of “Yes” from the user. For this we use SendGrid’s Inbound Parse Webhook.

var inbound = {
  index: {
    handler: function () {
      var request = this;
      var payload = request.payload;

      console.log(payload);

      if (payload.envelope) { envelope  = JSON.parse(payload.envelope) };

      var reply_html = payload.html.replace(c.BODY, "").toLowerCase();

      if (reply_html.indexOf("yes") >= 0) {
        Reminder.answeredYes(envelope.from, function(err, res) {
          request.reply({success: true});
        });
      } else {
        console.log("Reply did not include 'Yes'");

        request.reply({success: true});
      }
    }
  }
}

I’m using hapijs to build the /inbound route. That route captures the payload delivered by SendGrid, parses it, and checks for a “Yes” response. If there is a “Yes” response, it marks the Reminder as answered “Yes,” and doesn’t send another reminder until the next day.

The final step is to add this URL route to the incoming email settings. If you’re new to this concept, you might also want to check out my introduction to the Parse Webhook.

Your settings should look something like this:

Full instructions are on GitHub. Enjoy the rest of 2014 and show off those pearly whites!

For more details on the feature behind incoming email, download the Parse Webhook Guide for free now.


Programmer and tinkerer. Fledgling Devangelist @SendGrid. Follow me @scottmotte.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>