You need to have an account at twilio.com.
I used a free trial account to make this demo application.
You need to take for you a number on that support Twilio SMS. I got one in the US to send SMS to my country.
Open your Visual Studio and create a new Project with Windows Form Application.
This will make your Windows Form with Form1.cs and Form1.cs [Design].
You need to install with Visual Studio the Twilio-CSharp library.
This library lets you write C# code – go to Visual Studio menu:
Tools > NuGet Package Manager > Package Manager Console and use this command to install the twilio-CSharp library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | PM> Install-Package Twilio Attempting to gather dependency information for package 'Twilio.4.7.2' with respect to project 'twilio001', targeting '.NETFramework,Version=v4.5.2' Gathering dependency information took 737.94 ms Attempting to resolve dependencies for package 'Twilio.4.7.2' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms Resolving actions to install package 'Twilio.4.7.2' Resolved actions to install package 'Twilio.4.7.2' Retrieving package 'Twilio 4.7.2' from 'nuget.org'. Retrieving package 'RestSharp 105.2.2' from 'nuget.org'. GET https://api.nuget.org/packages/restsharp.105.2.2.nupkg GET https://api.nuget.org/packages/twilio.4.7.2.nupkg OK https://api.nuget.org/packages/restsharp.105.2.2.nupkg 70ms Installing RestSharp 105.2.2. OK https://api.nuget.org/packages/twilio.4.7.2.nupkg 286ms Installing Twilio 4.7.2. ... Successfully installed 'Twilio 4.7.2' to twilio001 Executing nuget actions took 10.06 sec Time Elapsed: 00:00:13.6427227 PM> |
Find the Toolbox ( Ctrl+Alt+X keys ) and add one button to your Windows Form.
Under Form1.cs [Design] press double left click with the mouse on Button ( is named button1 ).
This will open the Form1.cs and add this source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Twilio; namespace twilio001 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { var accountSid = "your_account"; // Your Account SID from www.twilio.com/console var authToken = "your_token"; // Your Auth Token from www.twilio.com/console var twilio = new TwilioRestClient(accountSid, authToken); var message = twilio.SendMessage( "+1111111", // From (Replace with your Twilio number) "+1111111", // To (Replace with your phone number) "Hello from C# and Twilio SMS messages!" ); if (message.RestException != null) { var error = message.RestException.Message; } } } } |
Fill with your accountSid, authToken and your number mobile phone from your twilio account console.
Save the file Form1.cs and then Build and Run the application.
Press the button to send the SMS message and you will see this output: