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.
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:
With these .dll files you can easily communicate with Plivo API.
Download these .dll files:
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: