Send Business Cards via SMS with Twilio and Google App Engine
Time to read: 3 minutes
Robert used Google App Engine to create a new, easy way to distribute business cards via Twilio SMS. With the Twilio API, and Google App Engine’s scalable infrastructure, he had his app up and running fast.
In this post, Robert explains how to send business cards directly to email via SMS.
Have you ever met someone but are out of business cards? This was the exact situation I was in when I ran into the Twilio folks at a conference. I absolutely hate carrying bulky business cards, and then I thought, this would be a perfect idea for building a Twilio app that lets you send virtual business cards using SMS.
Several years ago there was a startup called DropCard that did this, but they’re no longer around. I thought I’d take a stab at building this app myself so I built SwapCard. This was my first project using Twilio and I found it delightfully easy to get started. I was able to get SwapCard up and running in a matter of days. Check it out! You can starting sending business cards at www.swapcard.co.
Build your own SMS to email app!
I’ll show you a very basic example in Python of how you can create a simple app on App Engine that lets you text an email address to a Twilio number which then has your App Engine app send a message to that email. This involves setting up your Twilio account to get your Twilio number and building a simple App Engine app that handles the requests from Twilio. Here’s how it works:
- You text an email address to your Twilio number
- Your Twilio number will point to your App Engine app
- Your App Engine app sends an email to the email address you texted
- Your Twilio number texts you back a confirmation that an email has been sent
Setting up the App Engine app with webapp2
First we’re going to build an app using App Engine that will send an email once that url is called as well as use the Twilio API to send a SMS confirmation.
The first step is to register your application at cloud.google.com and create a project.
App Engine provides a simple webapp2 framework we’ll be using. It also provides a very easy to use Mail API. I suggest using the App Engine launcher to create your application as it provides all the necessary foundational files. Create a new application using the App Engine launcher.
Open up main.py in an editor.
Setting up Twilio
Now we’ll add the code that will use the Twilio API to send a confirmation SMS back to the user. First, you’ll have to download the twilio-python library. You’ll also need its dependencies of httplib2 and six. Copy these libraries into your application folder. You’ll also need to sign up for an account at Twilio.com.
You need to import the library into your app and add your account SID and auth token, which you can find at the top of your Twilio account.
Now we just need to add to the bottom of the SendEmail handler the code to send the sms.
The final product should look like this.
Deploy your application. You can also download the project source files on github at https://github.com/robertdo/twilio-gae
Setting up a Twilio phone number
Now that your app is live, all you need to do is set up a Twilio phone number that points to that app whenever it receives an SMS.
Log into your account at Twilio.com and get a phone number.
In the settings for that phone number, change the SMS request URL to be http://.appspot.com
This tells Twilio to point to that URL whenever that phone number receives an SMS.
Now try texting an email address to your Twilio number. An email should be sent to that email address and you should get an SMS confirmation.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.