Build an SMS-to-email gateway using Plivo and Mailgun API

We’ll show you how to set up your free Email-to-SMS gateway that will give you the power to receive free SMS notifications in your email inbox and allow you reply to that SMS directly from your email. We’ve partnered with our friends at Mailgun so that you can build this entirely free of charge using your free Mailgun account and your free Plivo account.

Configure Your Plivo Credentials

Add your Plivo Credentials

Your Email-to-SMS gateway will first require you to configure your Plivo Credentials. You can set these config variables in Heroku using your console. Check out Heroku’s variable configuration tutorial if you need help.

You can get your PLIVO_AUTH_IDand PLIVO_AUTH_TOKENfrom your Plivo Dashboard.

Use any of your Plivo phone numbers found on your Numbers tab in the Plivo Dashboard to PLIVO_NUMBER. If you don’t yet have a number, you can claim your free local US phone number in the Numbers tab if you click on the “Claim your free local US number” link.

Let Plivo know where your Email-to-SMS gateway app is and what to do with it

Create a Plivo application and point it to the Plivo number you purchased. Open the Applications Tab in your browser. Click on the New Applicationbutton to create an application. Give a name to your application (next to Application Name), lets call it ‘SMS Forward’. Fill out the following Application credentials and click “Create”. Be sure to set your Answer urland Message urlto:

Assign a Plivo phone number to your app: attach your SMS Enabled Plivo phone number to your newly created “ SMS Forward” application. Go to the Numbers tab and select the phone number you want to use for this app. Then select the name of your app next to Plivo App Click ‘Update’ when done.

Your phone number set up should now look like this:

Testing your App Locally (optional)

This is an optional step, but it’s always good practice to ensure that all your code is correct. So before we go any further, let’s run the app locally and make sure everything is working properly.

First, set up your DNS (Domain Provider or 3rd Party) to allow Incoming emails of your domain (i.e., my.yourdomain.com) to Mailgun. For us, we are showing how to set up our record values on Amazon Web Services EC2 Route53. In this example, the domain is plivo.com and we have set up my.plivo.com as the email domain for this service. A zone editor is similarly available for most domain providers, where the values are set as per the example.