How to send SMS Messages to Mobile in C#

By FoxLearn 7/16/2024 9:04:08 AM   24.76K
To send an SMS using Clickatell in a C# Windows Forms application, you need to follow these steps.

First off, You can open your Visual Studio, then create a new Windows Forms project called SmsMessages

How to send SMS Messages to Mobile in C#

Next, Open your form designer then drag and drop Label, Button, TextBox controls into your form designer.

send sms clickatell

You can layout your form as the figure above.

Finally, Add a click event handler to the Send button that allows you to send sms messages in c#.

To send SMS messages to mobile numbers using Clickatell in C#, you can use the Clickatell HTTP API.

Here's a basic example of how you can achieve this

First, you need to sign up for a Clickatell account and obtain your API credentials. By default, when you sign up for an account you have 5 free SMS.

private void btnSend_Click(object sender, EventArgs e)
{
    try
    {
        WebClient client = new WebClient();
        //Call web api to send sms messages c#
        Stream s = client.OpenRead(string.Format("http://api.clickatell.com/http/sendmsg?user=YOUR USERNAME&password=YOUR PASSWORD&api_id=YOUR_API_KEY&to={0}&text={1}", txtTo.Text, txtMessage.Text));
        StreamReader reader = new StreamReader(s);
        string result = reader.ReadToEnd();
        MessageBox.Show(result, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

Remember to replace YOUR_API_KEY with your actual Clickatell API key. This code sends a simple HTTP GET request to Clickatell's API endpoint with the necessary parameters.

Ensure you handle any exceptions that may occur during the HTTP request, such as network issues or invalid API responses. You can easily use the WebClient class to consume web api in c#

VIDEO TUTORIAL