Mobile application development is a modern process used for intelligent mobile phones. With the increased adoption of the internet and technology, most people have smart devices and are now adapting to their daily tasks from mobile applications. So, SMS has become one of the essential features of mobile devices. Almost all mobile applications use SMS features in many cases, such as validating the phone number, resetting passwords, and using two-factor authentication.
C# is one of the popular technologies among developers. As a result, there are multiple SMS APIs to use the SMS notification feature during developing applications using C#.
This article will discuss three ways to Send text messages (SMS) with the C#.
Using Twilio API
Twilio API is one of the most popular APIs used to send SMS. You can use Twilio API to send SMS for your mobile application easily. It's a programmable method you can integrate with your application.
Pros of using Twilio API
- Support for multiple programming languages.
- Good documentation.
- Easy to use for development.
Cons of using Twilio API
- It's a programmable platform and very hard to adapt to without a programming background.
- Expensive compared to other APIs.
Tutorial: How to Send SMS Using Twilio API & C#
Here, We are using the console application using the C# to demonstrate how to use Twilio API to send SMS. You can create a free trial account using the below link.
You need to install the Twilio NuGet package for your C# application.
- Install the Twilio 5.81.0 version.
You need to configure and get the virtual phone number to send SMS using Twilio. Then you can use the Twilio virtual number to send an SMS to your phone number. Also, you can get your Twilio account SID and Twilio auth token from the console dashboard like the below figure.
Now you can open the program.cs file using visual studio 2022. Then use the Twilio NuGet package to create the Twilio client, and then use
Create method of
MessageResource to create and pass the SMS to the Twilio service to send the SMS.
Before running the application, you must enable geo permission for your number if you use the trial version. In that case, you can enable your geo permission using this link.
Note - You must also verify your number if you are using the trial account. You can verify your number using the below link.
You can successfully send SMS using the Twilio in C# application as we did here.
Using the MessageBird API
Messagebird is a cloud communications platform that enables the sending and receiving SMS text messages using web service APIs. MessageBird offers several SMS delivery methods. You may send SMS messages using email or an API connection.
Pros of using MessageBird API
- User-friendly UI.
- Good Documentation.
Cons of using MessageBird API
- There are some deliverability problems with some mobile numbers.
Tutorial: How to Send SMS Using MessageBird API & C#
Here, We are using the console application using the C# to demonstrate how to use MessageBird API to send SMS. You can create a free trial account using the below link.
After creating the account, You can get a test access key from the dashboard like the below figure.
Then, You can install the MessageBird NuGet package for the console application.
- Install MessageBird 4.0.0 version
Now you can open the program.cs file using visual studio 2022. Then use the MessageBird NuGet package to use the
Client class and then use
CreateDefault method of
Client to create the client. Then use the
SendMessage method of the Client class to send the SMS. There are three method parameters in the SendMessage method. They are the originators (the sender), the SMS body, and the receivers.
Now you can get the response. If you get any error, You will get the error with the error code. They also have good documentation for error codes and handling errors. Then you can refer to it according to the error.
Using Courier Multi-Channel Notification API
Multi-channel notification API is a service that sends notifications through many channels like email, messages, WhatsApp, Slack, etc. For example, the Courier provides a multi-channel notification API using the uniform API to send information to all media users.
Pros of using a Multi-Channel Notification API
- You can use multiple channels to send SMS.
- You can use very small code-block and even use multiple channels.
- Non-technical users also can manage SMS services.
Cons of using a Multi-Channel Notification API
- Cost can be increased when using many channels.
Tutorial: How to Send SMS Using Courier API & C#
Here we are using Courier multi-channel notification API with C# console application for this demonstration. Courier supports popular SMS providers like Twilio, Pivilio, MessageBird, etc. We are using the MessageBird service with the Courier.
Here you can create a Courier account using the below link.
After login into the account, you need to create the channel using one of the SMS providers. We'll use MessageBird for this example.
Here, you have to add originating Number and Access Key and then click the Install Provider button.
After creating the channel, route to the designer tab to create a notification. Here, you need to click the Create Notification button like the below figure.
Here, You should have to create a notification. Then, you must select SMS as the channel and MessageBird as the service provider to send via Courier.
Then, click the Publish Changes button and move to the Preview tab. Here, click the Create Test Event button to create a new event.
Using Courier Multi-Channel Notification API with C#
After creating the event, move to send tab, and then you can find the API used to send SMS and its examples. You can also find the Auth Token to access APIs.
Here, we will access Courier APIs using the
HttpClient in C#. First, create the data object you need to send for the HttpPost request. Here you need to convert the object into a JSON object using the
Then, create the instance for HttpClient to access the Courier send API.
After that, You need to get the response. Here, you need to deserialize the JSON string to the response object. In that case, you need to create the response class.
Then, you need to deserialize the JSON string using the ResponseDto class.
We can send SMS using the Courier Multi-channel notification API very quickly. Here is the complete code block used for C# in this example.
This article demonstrated three SMS APIs used in C#, the pros and cons of the APIs, and how to use them with your C# applications. I hope the information in this article made it easier for you to decide on the best service for your application.
Thank you for reading.