Home
RECOMMENDED FOR YOU:
SMS Gateway software
Ozeki brings you outstanding
SMS Gateway technology. Use our SMS Server products on Windows,Linux, or Android

C# SMS API
Developers can use our C# SMS API to send SMS from C#.Net. The C# SMS API comes with full source code

PHP SMS API
The ozeki PHP SMS gateway software can be used to send SMS from PHP and to receive SMS usig PHP and MySQL on your website

SMPP SMS Gateway
SMS service provider use our SMPP gateway solution, that offers a high performance SMPP server and SMPP client gateway with amazing routing capabilities
Ozeki 10 SMS Gateway

C# SMS API with full source code

If you are looking for a powerful tool for C#.Net developers to add SMS sending and receiving capability to your C#.Net application, the C# SMS api provided by Ozeki SMS Gateway is your best option. It offers instant information about your submitted messages in the form of submit reports and delivery reports. It allows you to schedule SMS for future delivey, and you can receive SMS from mobile phones without delays. Learn more about what this C# SMS API is, and how you can use it in your environment.

What is a C# SMS API?

A C# SMS API is a software interface that allows you to send and receive SMS from C#.Net code. A C# SMS API is offered by an SMS gateway such as Ozeki SMS Gateway.

How does the C# sms api work?

With the C# SMS API you can send SMS messages, receive SMS messages much more efficiently than using traditional HTTP or REST SMP API solutions. The Ozeki C# SMS API creates and maintains a permanent link to the SMS gateway, and communicates over a highly optimized SMS protocol called OZX. It requires fewer resources in terms of CPU, memory and network bandwidth than other SMS protocols. Thanks to the permanent link, your C# sms application will receive instant submit reports and delivery reports in the form of C# events. You will also receive incoming SMS messages without any delays.

This is the best C# sms api in 2021.

What is the key to Ozeki C# SMS API being the best?

Since the amount of data needed to send an SMS is smaller, and the protocol transaction carries significantly less overhead, your solution will consume less resources in all three major areas: memory, cpu resources and network bandwidth. As a result of this they will act faster and will become more responsive.

How can I use the C# SMS API?

A C# SMS API is a set of C# classes, that enable you to send and receive SMS messages. The Ozeki C# SMS API can send SMS over Android mobile phones and Windows SMS Gateway systems. Message sending is done using C# method calls, and incoming messages arrive in the form of C# events.

What is c# sms api?
Figure 1 - How does the C# sms api work

The C# sms api is a C# library, that is provided to your free of charge, with an MIT license. You can freely modify it and distribute it as you wish. When you download the C# sms api, the package contains an example C# sms console application and the full source code of the Ozeki.Libs.OZX dll.

C# SMS API download

You may download the C# SMS API from the following link:
Download: OzekiConsole.zip (51 Kb)
URL: https://ozeki-sms-gateway.com/attachments/5755/OzekiConsole.zip

How does the C# SMS API work

The C# sms api can be used to send SMS text messages through your mobile phone or through an Ozeki SMS Gateway system installed on your Windows or Linux computer. When you send SMS through your mobile phone (Figure 1), you need to install the Ozeki android sms gateway software on your mobile and you need to connect to it through Wifi. You must keep in mind that android mobile phones cannot send more then a few thousand text messages per day. If you need a high performance on premises SMS gateway system, where several thousand (or million) messages can be sent and received, you need to install Ozeki SMS Gateway to a server computer (Figure 2). You may also install it to a virtual machine.

Ozeki SMS Gateway installed on a server
Figure 2 - Ozeki SMS Gateway installed on a server

Once you have the SMS gateway setup and ready, you need to create an OZX user in it to let your C# SMS client code connect to it. When you create the OZX user, you create a username and password. Your need to enter this username and password into the C# SMS API connect method. In the connect method you also have to provide the hostname or IP address and the port number of the mobile phone or windows pc where the SMS gateway is installed to.

The SMS gateway can be installed on the same computer where you develop your C# application using the C# sms api. In this case you would supply "127.0.0.1" as the IP address and port "9580" in the connect method. (Yes, you can also use IPv6 address or hostnames, such as 'localhost")

What is OZX?

OZX stands for OZeki eXchange. It is a highly optimized SMS protocol used to communicate between your C# SMS application and the Ozeki SMS Gateway. It is a TCP/IP based protocol that is significantly more efficient than traditional SMS protocols, such as C# HTTP SMS API protocols, C# REST SMS API protocols or the SMPP SMS protocol. The efficiency comes from two major facts: no unneccary data is transmitted (note that there is huge data overhead in both http and smpp), and an easier more efficient protocol processing is possible due to the protocol PDU structure.

What is in the C# SMS API zip?

The zip file contains two projects: a console application that is a very easy to understand code to show you how to use the C# SMS api, and it contains the source code of the C# SMS api itself.

C# SMS api Package contents:

  • Example code (full source code)
  • Ozeki client library (full source code)

Figure 1 - C# SMS API package contents

How do I open the C# SMS API .sln solution?

To open the Ozeki SMS API you need to locate the OzekiConsole.sln file after unzipping the OzekiConsole.zip package, and you need to open this file in Visual Studio. You may double click on the solution file (.sln), or you may navigate to it in Visual Studio.

Figure 1 - Open the OzekiConsole.sln

Once you have opened the .sln, you will see two projects in your solution. The OzekiConsole project contains the example code that shows you how you can use the C# SMS API client library to connect to the SMS Gateway. The other project is the Ozeki.Libs.OZX dll project. This project contains the full source code of the the C# SMS API client library.

Figure 2 - C# sms solution

How to use the C# SMS API

To use the C# SMS API, you need to create a username and password in your SMS gateway. If you have installed your SMS gateway on your Android phone, you need to login to the phone using a webbrowser. If you have installed your SMS gateway on Windows or Linux, simply connect to it with your browser. If you have not yet installed your SMS gateway, setup it up now using one of the following setup instructions: How to setup my SMS Gateawy on Windows, How to setup my SMS gateway on Linux.

how to use the c# sms api
Figure 3 - How to use the C# sms api

How to use the C# SMS API in 10 simple steps:

  1. Download the Ozeki SMS Gateway
  2. Install an SMS tester connection
  3. Install an OZX user
  4. Create a username and password
  5. Enable communication logging
  6. Open your C# SMS project in Visual Studio
  7. Modify the C# code with the username and password
  8. Send a test SMS from C#
  9. Check the logs in the SMS gateway
  10. Simulate an incoming SMS with the test connection
  11. Do a live test with your Android phone

Benefits of using your own SMS Gateway

Free testing: It is very beneficial to operate your own SMS gateway, because you may test your SMS application free of charge. You may simulate incoming SMS messages, you may send test messages to the SMS gateway's test connection, and you may simulate SMS delivery reports indicating successful and failed delivery.

Unlimited performance testing: Once you have developed your SMS solution in C# it is likely that you want to do some performance testing. With Ozeki SMS gateway it is very easy to test your system with high volume of SMS messages. In most cases you will only send a few thousand SMS, but if asked by a client you can even do a test with several million messages. Check out the SMS performance test results we have conducted with Ozeki SMS Gateway with 1 000 000 SMS.

Easily switch providers: If you develop your C# code that works with Ozeki SMS Gateway, you will not have to worry about being locked into one SMS network or to one SMS service provider. You can use the same C# code and simply switch to another SMS service provider if you get a better deal by configuring the new provider's connection in the SMS gateway.

How to send SMS from C#

To send SMS from C# you need to add the the ozekisms.dll as a reference to your Visual Studio Solution. You may decide to the add the binary dll or you may add the project containing the source code. If you add the binary dll, your project will compile quicker, if you add the source code you will have better debug capabilities.

How to send an SMS text message from C#
Figure 4 - How to send a text message from C#

How to send SMS from C# using Visual studio:

  1. Download the Ozeki C# SMS library (zip file)
  2. Extract the zip file
  3. Open Microsoft Visual Studio
  4. Create a new console application
  5. In the solution explorer click "Add..."
  6. Select "Existing project"
  7. Browser for the OzekiSMSLibrary.csproj
  8. Click Open
  9. Add the "Ozeki" namespace to your console app
  10. Copy paste the example
  11. Send you first SMS using the SendMessage function

How to receive SMS in C#

To receive SMS from C# you need to setup your project the same way you would set it up for sending an SMS message. In short, download the ozekisms.dll as a binary or as source and add it to your project as a reference library. After this, you can create an instance of C# class and you may subscribe for the event that is called when an SMS is received.

How to receive an SMS text message using C#
Figure 5 - How to receive an SMS using C#

How to receive SMS using C# in Visual studio:

  1. Download the Ozeki C# SMS library (zip file)
  2. Open Microsoft Visual Studio
  3. Create a new console app or open one of your existing projects
  4. Add the C# SMS library to your C# solution
  5. Add the "Ozeki" namespace to your class
  6. Create an instance of the message class
  7. Sign up for the OnMessageReceived event
  8. Write the event handler code
  9. Set a break point in the event handler
  10. Send a test message
  11. Wait for the SMS to reach the breakpoint

C# SMS API full source code

//*********************************************************************
// Ozeki C# SMS API - v1.0.0
// Documentation: https://ozeki-sms-gateway.com/p_5755-c-sharp-sms-api.html
//*********************************************************************

using System;
using OZX;

namespace OzekiConsoleClient
{
    class Program
    {
        static OzxClient Client;

        //*************************************************************
        // Main
        //*************************************************************

        static void Main(string[] args)
        {
            createClient();
            printWelcome();

            string command = null;
            string parameters;

            while (command != "exit")
            {
                if (!_promptAvailable) printPrompt();
                readCommand(out command, out parameters);
                _promptAvailable = false;
                dispatchCommand(command, parameters);
            }
        }

        //*************************************************************
        // Read next command
        //*************************************************************
        static bool _promptAvailable;

        static void printPrompt()
        {
            Console.Write("> ");
            _promptAvailable = true;
        }

        static void readCommand(out string command, out string parameters)
        {
            command = Console.ReadLine();
            parameters = null;
            int paramSep = command.IndexOf(' ');
            if (paramSep > -1)
            {
                parameters = command.Substring(paramSep + 1);
                command = command.Substring(0, paramSep);
            }
        }

        static void dispatchCommand(string command, string parameters)
        {
            switch (command)
            {
                case "help":
                    printHelp();
                    break;
                case "exit":
                    Console.WriteLine("Thank you for using Ozeki Client!");
                    break;
                case "connect":
                    connect(parameters);
                    break;
                case "disconnect":
                    disconnect();
                    break;
                case "send":
                    send(parameters);
                    break;
            }
        }

        //*************************************************************
        // Commands / Welcome
        //*************************************************************

        static void printWelcome()
        {
            Console.WriteLine("**********************************");
            Console.WriteLine("* Welcome to Ozeki Client v1.0.0 *");
            Console.WriteLine("**********************************");
            Console.WriteLine("Type 'help' for available commands");
        }

        //*************************************************************
        // Commands / Help
        //*************************************************************

        static void printHelp()
        {
            Console.WriteLine("**********************");
            Console.WriteLine("* Available commands *");
            Console.WriteLine("**********************");
            Console.WriteLine("help");
            Console.WriteLine("connect [host:port] [username] [password]");
            Console.WriteLine("disconnect");
            Console.WriteLine("send [recipient] [message]");
            Console.WriteLine("exit");
        }

        //*************************************************************
        // Commands / Connect
        //*************************************************************

        static void connect(string parameters)
        {
            if (!parseConnectParameters(parameters, out string host, out int port, out string username, out string password, out string errormessage))
            {
                Console.WriteLine("Error. "+errormessage);
                Console.WriteLine("Syntax: connect [host:port] [username] [password]");
                Console.WriteLine("Example: connect 127.0.0.1:9580 testuser testpass");
            }
            Console.WriteLine("Connecting to "+parameters+"...");
            Client.Connect(host, port, username, password);
        }

        static bool parseConnectParameters(string parameters, out string host, out int port, out string username, out string password, out string errormessage)
        {
            string[] parts = parameters.Split(' ');
            if (parts.Length < 3)
            {
                errormessage = "Connect expects 3 parameters.";
                username = null;
                password = null;
                host = null;
                port = 0;
                return false;
            }

            string hostandport = parts[0];
            username = parts[1];
            password = parts[2];

            string[] hostandportparts = hostandport.Split(':');
            if (hostandportparts.Length < 2)
            {
                errormessage = "Invalid host and port.";
                host = null;
                port = 0;
                return false;                
            }

            host = hostandportparts[0];
            string portstring = hostandportparts[1];

            if (!int.TryParse(portstring, out port))
            {
                errormessage = "Invalid port number.";
                port = 0;
                return false;
            }

            errormessage = null;
            return true;
        }

        //*************************************************************
        // Commands / Disconnect
        //*************************************************************

        static void disconnect()
        {
            Client.Disconnect();
        }

        //*************************************************************
        // Commands / Send
        //*************************************************************

        static void send(string parameters)
        {
            string[] parts = parameters.Split(new char[] { ' ' },2);
            if (parts.Length < 2)
            {
                Console.WriteLine("Error. Send expects 2 parameters.");
                Console.WriteLine("Syntax: send [recipient] [message]");
                Console.WriteLine("Example: send +441234567 Hello world");
                return;
            }

            string recipient = parts[0];
            string message = parts[1];

            var msg = new OzxMessage();
            msg.ToAddress = recipient;
            msg.Text = message;

            Console.WriteLine("Sending message. ID: "+msg.ID);
            Client.Send(msg);
        }

        //*************************************************************
        // Create client
        //*************************************************************
        static void createClient()
        {
            Client = new OzxClient();
            Client.AutoReconnect = true;

            Client.OnMessageReceived += Client_OnMessageReceived;
            Client.OnMessageAcceptedForDelivery += Client_OnMessageAcceptedForDelivery;
            Client.OnMessageNotAcceptedForDelivery += Client_OnMessageNotAcceptedForDelivery;
            Client.OnMessageSubmitSuccess += Client_OnMessageSubmitSuccess;
            Client.OnMessageSubmitFailed += Client_OnMessageSubmitFailed;
            Client.OnMessageDeliverySuccess += Client_OnMessageDeliverySuccess;
            Client.OnMessageDeliveryFailed += Client_OnMessageDeliveryFailed;
            Client.OnMessageViewed += Client_OnMessageViewed;
            Client.OnConnected += Client_OnConnected;
            Client.OnDisconnected += Client_OnDisconnected;
        }

        //*************************************************************
        // Messaging events
        //*************************************************************

        static void Client_OnConnected(object sender, EventArgs e)
        {
            Console.WriteLine("Successfully connected.");
            printPrompt();
        }

        static void Client_OnDisconnected(object sender, OzxArgs< string > e)
        {
            Console.WriteLine("Connection closed. Reason: " + e.Item.ToString());
            printPrompt();
        }

        static void Client_OnMessageReceived(object sender, OzxArgs< IOzxMessage > e)
        {
            Console.WriteLine("Message received: " + e.Item.ToString());
            printPrompt();
        }

        static void Client_OnMessageAcceptedForDelivery(object sender, OzxArgs< string > e)
        {
            Console.WriteLine("Message accepted for delivery. ID: " + e.Item.ToString());
            printPrompt();
        }

        static void Client_OnMessageNotAcceptedForDelivery(object sender, OzxArgs< string, string > e)
        {
            Console.WriteLine("Message rejected. ID: " + e.Item1.ToString()+" Reason: "+e.Item2);
            printPrompt();
        }

        static void Client_OnMessageSubmitSuccess(object sender, OzxArgs< string, DateTime > e)
        {
            Console.WriteLine("Message submitted. ID: "+e.Item1+" Date: "+e.Item2);
            printPrompt();
        }

        static void Client_OnMessageSubmitFailed(object sender, OzxArgs< string, DateTime, string > e)
        {
            Console.WriteLine("Message submit failed. ID: " + e.Item1 + " Date: " + e.Item2+" Reason: "+e.Item3);
            printPrompt();
        }

        static void Client_OnMessageDeliverySuccess(object sender, OzxArgs< string, DateTime > e)
        {
            Console.WriteLine("Message delivered. ID: " + e.Item1 + " Date: " + e.Item2);
            printPrompt();
        }

        static void Client_OnMessageDeliveryFailed(object sender, OzxArgs< string, DateTime, string > e)
        {
            Console.WriteLine("Message delivery failed. ID: " + e.Item1 + " Date: " + e.Item2 + " Reason: " + e.Item3);
            printPrompt();
        }

        static void Client_OnMessageViewed(object sender, OzxArgs< string, DateTime > e)
        {
            Console.WriteLine("Message viewed. ID: " + e.Item1 + " Date: " + e.Item2);
            printPrompt();
        }
    }
}

Final thoughts

To sum it up the C# SMS API allows you to connect to your SMS Gateway using the OZX protocol. This SMS protocol offers excellent performance and two way SMS communication. The fact that the free to use C# SMS API library provided by Ozeki allows you to send SMS messages with simple method calls, and to receive SMS submission and delivery reports in the form of C# events makes this option the possible option if you wish to build a C# SMS application in 2021.