Integration Guide – How to send SMS with Twilio in ASP.NET and C#

Integration Guide – How to send SMS with Twilio in ASP.NET and C#

In this tutorial I will explain you how to use Twilio to send SMS using C# and ASP.NET. You can send SMS to any phone number and anywhere in the world. Let us first introduce you to Twilio.

What is Twilio

Twilio allows making and receiving phone calls and also sending and receiving text messages, using its APIs. Programmers can implement Twilio APIs in their code and create all sort of applications involving phone calls and SMS. It’s services are accessed over HTTP and are billed based on usage. It can be used easily in our application for creating features like SMS authentication, OTP, SMS marketing and more.

I have also written a similar tutorial for sending SMS using PLIVO. You should also check that tutorial after you have read this one.

Twilio SMS

In this tutorial I will create a simple code which will send SMS to a mobile number using Twilio API.

Follow the steps outlined below –
  • STEP 1: Create your account in Twilio to get API credentials.
  • STEP 2: Reference the Twilio.Api.dll file in your website. You can download this file by using the download link given at the last of the tutorial. Alternately you can also reference this file from Visual Studio Nuget Package Manager Console. Type Install-Package Twilio and press enter key.
    twilio api
  • STEP 3: Add reference to Twilio namespace in your web page. Eg using Twilio;.
  • STEP4: Add the following code in your page load event.
protected void Page_Load(object sender, EventArgs e)
{
    string AccountSid = "Your Twilio Account Sid";
    string AuthToken = "Your Twilio Auth Token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);
    var message = twilio.SendMessage("+13343164589", "+919818924213", "Jenna please?! I love you", "");
}
Do you want to explore Bootstrap from the beginning. Then kindly check this tutorial on What is Bootstrap which will explain you this framework from the starting point.

Note that in the above twilio.SendMessage() function has 3 parameters –

a) First Parameter – the twilio phone numbers which you can get from the twilio API. The cost of this number starts from $1 per month.

b) Second Parameter – the number to which you have to send the SMS.

c) Third Parameter – the SMS message

For using helper libraries in other languages like php, perl, C++, phython, Java etc visit – https://www.twilio.com/docs/libraries

Download Codes:

Download

Are your starting with ADO.NET programming, then you should look into this very first tutorial which explains how to Insert Data in a Database using C# and ASP.NET.

SHARE THIS ARTICLE

  • linkedin
  • reddit
yogihosting

ABOUT THE AUTHOR

I hope you enjoyed reading this tutorial. If it helped you then consider buying a cup of coffee for me. This will help me in writing more such good tutorials for the readers. Thank you. Buy Me A Coffee donate