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

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

In websites we see the feature of sending SMS to customers mobile numbers. This is done for a number of reasons like sending one time password (OTP), authentication, marketing and more. You can also add SMS sending feature in your website very easily using Plivo. which is a Global SMS & Voice calls service.

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

Plivo SMS API

In this tutorial I will teach you how to send SMS using Plivo SMS API in your ASP.NET website. First you need to create your account in Plivo website and generate AUTH ID and AUTH TOKEN. With these ‘Auth Id and Auth Token’ you can communicate with Plivo API to send SMS to any desired mobile number.

Next, in your ASP.NET website’s Bin folder include two .dll files:

  • 1. Plivo.dll
  • 2. RestSharp.dll

With these .dll files you can easily communicate with Plivo API.

Download these .dll files:

Download

Adding Plivo.dll to Bin Folder

Adding Plivo.dll to Bin Folder

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.

I have listed the code for sending SMS. First include the following namespace in your web page.

using RestSharp;
using Plivo.API;
using System.Collections.Generic;

Code for Sending SMS using Plivo API –

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            bool result = SendSms("+919123451234", "+919871552204", "Send SMS using Plivo");  	 		
    }

    public bool SendSms(string from, string to, string text)
    {
        string authId = "Your Plivo authId";
        string autoToken = "Your Plivo authToken";
        RestAPI plivo = new RestAPI(authId, autoToken);
        IRestResponse resp = plivo.send_message(new Dictionary<string, string>() 
        {
            { "src", ""+from+"" }, // Sender's phone number with country code
            { "dst", ""+to+"" }, // Receiver's phone number with country code
            { "text", ""+text+"" }, // Your SMS text message
            // To send Unicode text
            // {"text", "こんにちは、元気ですか?"} // Your SMS text message - Japanese
            // {"text", "Ce est texte généré aléatoirement"} // Your SMS text message - French
            { "url", "http://dotnettest.apphb.com/delivery_report"}, // The URL to which with the status of the message is sent
            { "method", "POST"} // Method to invoke the url
        });
        return true;
    }
}

The good thing using Plivo is that you can send Global SMS too in very cheap price. All new users get $2 free trial amount for sending SMS. Use it to do testing of your application without spending any SMS money.

Download codes:

DOWNLOAD

Would you like to dig deep into the world of database programming with C#? Then you can check this series of tutorials on Entity Framework Core that help you to learn database programming within a few hours time.

Share this article -

yogihosting

ABOUT THE AUTHOR

This article has been written by the Technical Staff of YogiHosting. Check out other articles on "WordPress, SEO, jQuery, HTML" and more.