Introduction
In modern web applications, the business may require to send SMS to end-users in various scopes like Alerting the users, acknowledging the users, or even sending OTP. Sending as SMS is the easiest way and also can be implemented easily in .NET applications using Twilio.
Setting Up Twilio Account
Twilio two-way SMS and MMS messages allow you to carry on a conversation by both sending and receiving text and multimedia messages. This can enable a contact center agent to engage in an SMS-based chat with a customer, or let customers re-schedule appointments via text and receive automated responses.
- Try / Create a free account – https://www.twilio.com/try-twilio

- Choose the Service which we want like SMS, WhatsApp, Voice and etc from the option.


- Get a Virtual Twilio Phone Number to Send & Recieve SMS

“To send or receive an SMS with Twilio, you will need a virtual phone number from Twilio. A virtual phone number is a standard telephone number that is not locked down to a specific phone. It can route a voice call or text message to any phone or application workflow. In addition, you will need a Twilio Account SID and Auth token to connect Twilio with your application.”
Sending SMS in.NET Application
For this article example, let’s create a simple Blazor application that has one UI with two fields, one is to enter the Receiver Phone Number and another is for Message Content.
Choose Visual Studio -> Create a new Project -> Blazor WebAssembly APP
Install the required Twilio NuGet package, for that navigate to Tools and search Twilio.

“Twilio’s NuGet package for .NET helps you to create a new instance of the Message resource, specifying the To, From, and Body parameters of your message. Let’s create a new .NET project and add the Twilio NuGet Package.”
C# Code Implementation
Declare variables for Phone Number, Message Content, Twilio Account SID, and Twilio Auth Token.
public string MessageContent { get; set; }
public string PhoneNumber { get; set; }
public string accountSid = "Paste your Account SID from the Twilio Account";
public string authToken = "Paste your Auth Token from the Twilio Account";
public string TwilioSenderNumber = "Paste your Twilio Phone Number from the Twilio Account";
Create a method which is to send SMS,
protected void SendMessage()
{
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
body: MessageContent,
from: new Twilio.Types.PhoneNumber(TwilioSenderNumber),
to: new Twilio.Types.PhoneNumber(PhoneNumber)
);
}
Now run the application and enter the receiver’s phone number and message content.

Now the SMS is received by the receiver and it will be as,

Conclusion
In this simple article, we discussed how to send SMS using Twilio in C# and the .NET applications. We will discuss more on this in upcoming articles. I hope you all liked this article and please feel free to share your feedback in the comment section.
Article References and Credits
The Italic Paragraphs are taken as it is from the official Twilio site.
Leave a Reply