In a previous blog post, I showed you how to remember people's names with a digestible daily email
. I've been using the approach daily.
It has been helpful but has had one big downside: it requires me to make an API call by hand every time I want to add a person to the database. This is tedious. Let's change that by automating it.
SendGrid's Parse API
can help us here.
The majority of people's names I want to remember are people I have interacted with over email. Likely I met them in person, followed up with them over email, and might run into them again in my travels.
So let's forward all our emails to SendGrid's Parse API, pull out the email addresses from the contents of the email, and save that to our database. Now our database of people's names will automatically grow as our network grows.
To use the Parse API, we must add SendGrid's MX Record to a web domain we own. This will allow us to forward all emails to SendGrid's Parse API. Since it must take over email for an entire record, it's a good idea to use a sub-domain.
Go to your domain's DNS dashboard and add the MX record m.yourdomain.com
with the value of mx.sendgrid.net
Next, setup the SendGrid Parse API. Go to http://sendgrid.com/developer/reply
. Set your hostname to m.yourdomain.com
and set your url as https://yoursubdomain.herokuapp.com/emails/parse
Now you can send an email to firstname.lastname@example.org
, and SendGrid's Parse API will receive it, and make a POST request to https://yoursubdomain.herokuapp.com/emails/parse
Awesome. Now, we can write the code to parse that incoming email data.
In app.js add the following code.