Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

delphi-send-sms-http-rest-ozeki

Delphi send SMS with Ozeki SMS Gateway

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

Delhi sms library to send sms with http/rest/json

This Delhi sms library enables you to send and receive sms messages with http request. The library uses HTTP Post requests and JSON encoded content to send the text messages to the mobile network1. It connects to the HTTP SMS API of Ozeki SMS gateway. This repository is better at implementing SMS solutions then other alternatives, because it is very user-friendly but also powerful enough to send 1000 SMS per second, while providing full service provider independence.

What is Ozeki SMS Gateway

Ozeki SMS Gateway is a powerful SMS Gateway software that you can download and install on your Windows or Linux computer or to your Android mobile phone. It provides an HTTP SMS API, that allows you to connect to it from local or remote programs. The reason why companies use Ozeki SMS Gateway as their first point of access to the mobile network, is because it provides service provider independence. When you use Ozeki, the SMS contact lists and sms data is safe, because Ozeki is installed in their own computer (physical or virutal), and Ozeki provides direct access to the mobile network through wireless connections.

Download: Ozeki SMS Gateway download page

Tutorial: Delhi send sms sample and tutorial

To send sms from Delhi

  1. Download Ozeki SMS Gateway
  2. Connect Ozeki SMS Gateway to the mobile network
  3. Create an HTTP SMS API user
  4. Checkout the Github send SMS from Delhi repository
  5. Install Delphi extension pack
  6. Open the Github SMS send example in Visual Studio
  7. Compile the Send SMS console project
  8. Check the logs in Ozeki SMS Gateway

How to use the code

To use the code you need to import the Ozeki.Libs.Rest sms library. This sms library is also included in this repository with it's full source code. After the library is imported with the using statement, you need to define the username, password and the api url. You can create the username and password when you install an HTTP API user in your Ozeki SMS Gateway system. The URL is the default http api URL to connect to your SMS gateway. If you run the SMS gateway on the same computer where your Delphi code is running, you can use 127.0.0.1 as the ip address. You need to change this if you install the sms gateway on a different computer (or mobile phone).

How to use the Ozeki.Libs.Rest unit

In order to use the Ozeki.Libs.Rest unit in your own project, you need to place the Ozeki.Libs.Rest.pas file in your project. After you've placed these two files (what you can download from this github repository, together with 5 example projects), you can import it with this line:

pascal
uses Ozeki.Libs.Rest in 'Ozeki.Libs.Rest.pas';

When you imported the header file, you are ready to use the Ozeki.Libs.Rest unit, to send, mark, delete and receive SMS messages.

Creating a Configuration

To send your SMS message to the built in API of the Ozeki SMS Gateway, your client application needs to know the details of your Gateway and the http_user. We can define a Configuration instance with these lines of codes in Delphi:

pascal
var configuration : Ozeki.Libs.Rest.Configuration := Ozeki.Libs.Rest.Configuration.Create;
configuration.Username := 'http_user';
configuration.Password := 'qwe123';
configuration.ApiUrl := 'http://127.0.0.1:9509/api';

Creating a Message

After you have initialized your configuration object you can continue by creating a Message object. A message object holds all the needed data for message what you would like to send. In Delphi we create a Message instance with the following lines of codes:

pascal
var msg : Ozeki.Libs.Rest.Message := Ozeki.Libs.Rest.Message.Create;
msg.ToAddress := '+36201111111';
msg.Text := 'Hello world!';

Creating a MessageApi

You can use the MessageApi class of the Ozeki.Libs.Rest unit to create a MessageApi object which has the methods to send, delete, mark and receive SMS messages from the Ozeki SMS Gateway. To create a MessageApi, you will need these lines of codes and a Configuration instance.

pascal
var api : Ozeki.Libs.Rest.MessageApi := Ozeki.Libs.Rest.MessageApi.Create(configuration);

After everything is ready you can begin with sending the previously created Message object:

pascal
var result : Ozeki.Libs.Rest.MessageSendResult := api.SendMessage( msg );

Writeln(result.ToString);

After you have done all the steps, you check the Ozeki SMS Gateway and you will see the message in the Sent folder of the http_user.

How to send sms through your Android mobile phone

If you wish to send SMS through your Android mobile phone from Delhi, you need to install Ozeki SMS Gateway on your Android mobile phone. It is recommended to use an Android mobile phone with a minimum of 4GB RAM and a quad core CPU. Most devices today meet these specs. The advantage of using your mobile, is that it is quick to setup and it often allows you to send sms free of charge. Android SMS Gateway

Get started now

Don't waste any more time, send your first SMS!