mailgun is a great service that handles the difficult parts of handling emails for developers. One of the features they offer is the ability to POST to an HTTP endpoint upon receiving an email. We’ll use this feature to have mailgun send a POST request to a plumber API when an email arrives to a certain email address. mailgun has a very generous free tier, so you can replicate this exercise without spending a dime.
After registering for a mailgun account, you’ll either need to use their sandbox, or configure a (sub)domain name to be hosted by mailgun. In my case, I setup
plumber.tres.tl to have its email hosted by mailgun. You could just as easily use
mailgun.myorg.com if you don’t want to disrupt email hosting on your production domain.
Once you have a domain setup, you just add a route that tells mailgun what to do with your email. In my case, I said that it should listen for emails sent to
email@example.com and, when one comes in, convert it to an HTTP POST request and send it to
This example will auto-refresh every 3 seconds with the latest emails the API has received. Try sending an email to firstname.lastname@example.org to see the API at work.