Windows Forms: Send SMS Message in C#

This post shows you how to send sms messages to mobile or cell phone via the internet using vianett api in c# .net windows forms application.

ViaNett is a sms gateway that helps you send text message from c# application to mobile phone via internet.

Drag the Label, TextBox and Button controls from the visual studio toolbox to your winform, then layout your UI as shown below.

send text message from c# application

Add the button click event handler to the Send button allows you to send a sms message to mobile or cellphone using sms gateway as the following c# code.

private void btnSend_Click(object sender, EventArgs e)
    using (System.Net.WebClient client = new System.Net.WebClient())
            string url = "" +
                "src=" + txtPhoneNumber.Text + "&" +
                "dst=" + txtPhoneNumber.Text + "&" +
                "msg=" + System.Web.HttpUtility.UrlEncode(txtMessage.Text, System.Text.Encoding.GetEncoding("ISO-8859-1")) + "&" +
                "username=" + System.Web.HttpUtility.UrlEncode(txtUsername.Text) + "&" +
                "password=" + System.Web.HttpUtility.UrlEncode(txtPassword.Text);
            //Call web api to send sms messages
            string result = client.DownloadString(url);
            if (result.Contains("OK"))
                MessageBox.Show("Your message has been successfully sent.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MessageBox.Show("Message send failure.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        catch (Exception ex)
            MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);

You can you the WebClient class to call c# send text message through vianett sms gatewate api, then get the result value returned from the api method. You can also use the code above to learn how to send sms using c# web application.

To play demo you need to create an account at vianett website, then you will get 5 free sms. ViaNett is working hard to ensure that any developer who wants to use the messaging gateway in their application, site or system can do so reliably and simply.

Through the c# example, you learned how to send free sms using c# windows application or how to send sms using api in c# net.