Send an SMS Message with .NET Core
Note:
Before you can get started, you need the following already set up:
- Set all SMS API configuration settings.
- The latest version of .Net Core with Long Term Support and a familiarity with how to create a new app.
Learn how to quickly send SMS messages in a .Net Core application with the Sinch API.
Set up your .Net Core application
- Create a new folder where you want your app project. Then, open a terminal or command prompt to that location.
- Create a new .Net Core console app with the following command:
dotnet new console
- Add the
Newtonsoft.Json
nuget package.dotnet add package Newtonsoft.Json
Modify your application
- Open the
Program.cs
file in your project folder. Replace everything in the file with the following code:SMS sms = new SMS("YOUR_Sinch_virtual_number", new string[] {"recipient_number"}, "Hello from Sinch!" ); sms.sendSMS(sms, "YOUR_servicePlanId", "YOUR_API_token"); Console.ReadLine();
- Next, create a new file in the project folder named
SMS.cs
. Populate that file with the "Send an SMS message" code found on this page. - Save the file.
Fill in your parameters
- Back in the
Program.cs
file, replace the following values for these parameters with your values:Parameter Your value YOUR_Sinch_virtual_number
Any number you've assigned to your Sinch account. Find the number on your Sinch dashboard by clicking the service plan ID link and scrolling to the bottom of the page. recipient_number
The phone number to which you want to send the test SMS message. YOUR_servicePlanId
The API token found on your Sinch dashboard. Click Show
to reveal your API token.YOUR_API_token
The service plan ID found on your Sinch dashboard. Double check that the region is correct on your base URL. Learn more about regional options here.
- Save the file.
Build your project
Before executing your code, you must first compile your application. Execute the following command:
dotnet build
Send your first SMS message
Now you can execute the code and send your test SMS message. Run the following command:
dotnet run
Enter
to exit the application. You did it!Next steps
The code you used in theSMS.cs
file sends a POST request to the Sinch API /batches
endpoint to send the SMS message. Click here to read more about the batches endpoint.Additional resources
- Explore the API specification to test more endpoints.