How to turn emails into text messages with two simple APIs

Want to improve customer experience? Learn how to easily turn emails into SMS.
Phone with green text message and arrow to email

Building a bridge between enterprise email and consumer SMS for better customer experiences

Still using email? Yup, me too.  It’s one of the first things a new employee receives after starting their job; an email address.

We can’t escape it, even though products like Microsoft Teams, Slack, RingCentral Glip, and Cisco Spark have made significant headway in reducing email clutter by enabling real-time collaborative communication in the enterprise.

But what about business to consumer communications? Advanced CRM tools allow enterprises to combine multiple channels into a single view. Social Media (Twitter, Facebook, Instagram), Email, Phone calls – All presented in a single panel.

But what happens when your audience wants to engage via SMS? Not all Enterprise CRM platforms have enabled SMS capabilities and many mature enterprises still issue desk phones to every employee. ICMI reported “74% of consumers use three or more channels to access customer service”. With 4.7 Billion mobile users in the world and SMS native to every mobile handset, it’s definitely a communication channel worth paying attention to.

Why use SMS instead of email?

Email is slow (by today’s standards), but engrained in nearly every business. SMS, by comparison, is fast, with high read and fast response rates by users.

Creating the perfect email and SMS gateway

Let’s define what our ideal solution would be where the transactional nature of SMS and the descriptive nature of email communications can come together.

The ideal email and SMS gateway would minimally have:

  • Ability to have two-way communications between an email address and any SMS-enabled phone number
  • Ability to send long messages (beyond the normal 160-character limit of a typical SMS)
  • Ability to send and receive attachments
  • Fast! The user should not even be aware that SMS is getting translated into an email
  • Easy! Easy to configure, deploy, manage, and educate users on how to use

Sure, you could probably buy an off-the-shelf solution, but why do that when you can build your own in just a few steps?

Implementing your email and SMS gateway in 5 steps

Implementing an SMS-Email gateway sounds like a tall order. There are email clients, email servers, MTAs, phone numbers, messaging protocols, and enough acronyms to make alphabet soup jealous.

Fortunately, we can narrow the scope of our problem by connecting the two communications channels through cloud-based email APIs and Bandwidth’s CPaaS for messaging.

A detailed instruction set, including code, is available here.

1. Configure Your Domain

You’ll need the help of your IT department here. First, set up a sub-domain for your enterprise that will handle all the email for your SMS-Email relay. Something like works nicely as it is descriptive of the intended use. The reason you need a sub-domain is that we’ll need to delegate DNS MX records to a 3rd party.

2. Set up an Email API

For this exercise, we’ve decided to use Mailgun, though you could pick any transactional email provider with a solid API. We like Mailgun because of their extensive documentation and generous starter tier. Simply create an account. Add the sub-domain created in Step 1. Then perform the DNS verification process .

The last step is to set up a “route”. We’ll do that after we deploy our code.

email to sms reporting dashboard
When we are all done, we should have a nice looking dashboard with email stats published similar to this.

3. Set up the Bandwidth Messaging API

Bandwidth SMS and MMS APIs are the obvious choices for this solution. If you don’t already have a developer account with Bandwidth, get one . You’ll need to create a new “application” and allocate at least one phone number to the application. Each number you allocate will be enabled for your Email-SMS relay.

You’ll need to tell Bandwidth where your code is living so the platform knows where to notify you when a new SMS comes in. Since we’ve not deployed our code yet, we’ll come back to this step.

4. Grab the code!

We’ve provided a sample application that will create an Email-SMS relay service for you. The code is located at All you need to do is host it on a server that allows public HTTP requests from Bandwidth and Mailgun.

There are a few items you’ll need to configure in the code before you can kick the tires.

  1. Add your API credentials
  2. Add a file called contacts.csv with your phone numbers <-> email address mappings.

You’ll also need to tell your API providers how to reach your code:

  1. Bandwidth: Set the callback URL to your web server in your configured application
  2. Mailgun: Create a catch_all() route that points to your web server.

5. Take it for a spin!

If everything was configured correctly, you should now have a fully functional Email-SMS relay.  Only users in the contacts.csv file are authorized to use the email relay.

All you need to now is send an email. Create a new email with the following fields:

  • From: valid email address in contacts.csv
  • To: [email protected]
  • Subject: phone number of recipient
  • Body: Whatever you want to appear in the text
A Gmail email composition window showing how to send a text message
Example of what your email composition window should look like.

Things you can try

  • Send an email and watch the message appear as an SMS on your cell phone
  • Attach a picture to on outgoing email and see it appear on your cell phone
  • From your cell phone, send an SMS to your business number in contacts.csv and watch it appear in your email box