Sending SMS is a common requirement these days for alerts, notifications, two factor authentications etc. Lot of SMS APIs and gateways are available like Twilio etc. and consuming those APIs programmatically from any programming languages is breeze but it comes with money.
For instance, Twilio costs 56 paise (.56 rupee) in INR (India Rupee) for sending 1 SMS which is lot of money if the volume is more. We found another provider Solutions Infini in Bangalore, India, they charge 20 paise (.20 rupee) INR if we buy in bulk of 25000 SMS lifetime validity for INR 5000/- . What-if if we get it for free without compromise in the reliability, response time etc. and the solution is using Google Calendar Event notification for sending out SMS.
Note: By any means this is not a complete solutions or replacement for Twilio or any other similar SMS service providers. It has its own limitations like
- The client or end user to whom the SMS is targeted should use Gmail [Should be okay in SME/SMB cases where the business email is Google Email]
- Only limited number of characters are allowed and most of it will be eaten up by the sender’s email id which is very long i.e. firstname.lastname@example.org
- Doesn’t provide hooks etc.
- And the number goes………………
Let us jump to the implementation:
Client Pre-requisite to receive SMS alerts
5) The client or end user to whom the SMS is targeted should use Gmail
6) The client or end user should have registered their mobile phone with Google Calendar mobile setup. The procedure is available here [https://support.google.com/calendar/answer/45351?hl=en]
Server Pre-requisite to send SMS programmatically using Google service account (un-attended UI)
1) Create a project in Google console https://console.developers.google.com/project [Screenshot -01]
2) Enable Calendar API from. Expand “APIs & Auth” in left menu and then click on APIs [Screenshot-02]
3) Click on calendar API and enable [Screenshot-03]
4) Click on credentials and create new client ID. Once done you will get the following [Screenshot-04]
- Email Address
- Public key fingerprints
- A key file with extension “.p12” will be downloaded. Keep this file in a safe place which we will be using while programmatically sending the SMS
- The C# source is self explanatory with example [embedded inside the comment] on how to invoke it from client.
- The SMS sender is written as class file [feel free to alter and optimize as per your wish & need]
- Important: Include the “.p12” file downloaded from the developer console in the root [change the path as per your wish]
- VS.NET 2012 / 13 with nugget package manager 2.8.1 and above