Login to your account: Login 

Posted on February 11th, 2010 by admin.
Categories: Technical

Example of a Delphi/Pascal Interface for the Bulk SMS Gateway / API

For more information regarding the bulk sending API click here.

A code example for sending SMS via a Delphi Pascal language, thanks to Graham Murt for the example code.

{*******************************************************************************
*                                                                              *
*                 TextMarketer Delphi/Pascal Interface                         *
*                                                                              *
********************************************************************************

{

  example use:

  procedure TForm1.Button1Click(Sender: TObject);
  begin
    SendTextMarketerSms(username, password, sender, recipient, message);
  end;

}

unit untTextMarketer;

interface

uses Classes, IdHttp;

const
  C_HTTP_URL  = 'http://www.textmarketer.biz/gateway/';

type
  TTextMarketerSMS = class
  private
    FHttp: TIdHttp;
    FPassword: string;
    FUsername: string;
  public
    constructor Create; virtual;
    destructor Destroy; override;
    function SendSms(AOriginator,
                     ANumber,
                     AMessage: string;
                     AXmlResponse: Boolean): string;
    property Username: string read FUsername write FUsername;
    property Password: string read FPassword write FPassword;
  end;

  function SendTextMarketerSms(AUsername, APassword, ASender, ANumber, AMessage: string): string;

implementation

uses SysUtils;

function SendTextMarketerSms(AUsername, APassword, ASender, ANumber, AMessage: string): string;
var
  ASms: TTextMarketerSMS;
begin
  ASms := TTextMarketerSMS.Create;
  try
    ASms.Username := AUsername;
    ASms.Password := APassword;
    Result := ASms.SendSms(ASender, ANumber, AMessage, True);
  finally
    ASms.Free;
  end;
end;

{ TTextMarketerSMS }

function UrlEncode(const DecodedStr: String): String;
var
  I: Integer;
begin
  Result := '';
  if Length(DecodedStr) > 0 then
    for I := 1 to Length(DecodedStr) do
    begin
      if not (DecodedStr[I] in ['0'..'9', 'a'..'z',
                                       'A'..'Z', ' ']) then
        if DecodedStr[I] = '£' then
          Result := Result + '%C2%A3'
        else
          Result := Result + '%' + IntToHex(Ord(DecodedStr[I]), 2)
      else if not (DecodedStr[I] = ' ') then
        Result := Result + DecodedStr[I]
      else
        begin
          Result := Result + '%20'
        end;
    end;
end;

constructor TTextMarketerSMS.Create;
begin
  inherited;
  FHttp := TIdHTTP.Create(nil);
end;

destructor TTextMarketerSMS.Destroy;
begin
  FHttp.Free;
  inherited;
end;

function TTextMarketerSMS.SendSms(AOriginator, ANumber, AMessage: string;
  AXmlResponse: Boolean): string;
var
  AResult: Boolean;
  AParams: AnsiString;
  AResponse: TStringList;
begin
  AResponse := TStringList.Create;
  try
    AParams := '';
    AParams := AParams + ('?username='+FUsername);
    AParams := AParams + ('&password='+FPassword);
    AParams := AParams + ('&number='+ANumber);
    AParams := AParams + ('&orig='+UrlEncode(AOriginator));
    AParams := AParams + ('&message='+UrlEncode(AMessage));
    if AXmlResponse then AParams := AParams + ('&option=xml');
    try
      Result := FHttp.Post(C_HTTP_URL+AParams, AResponse);
    except
      Result := '';
    end;
  finally
    AResponse.Free;
  end;
end;

end.

Popularity: 10%






Related posts:

  1. Using our short code and gateway APIs to create a game
    The Concept To create an interactive game using Text Messaging and to show how easy it is to create interactive...
  2. Bulk SMS API ASP Help
    Using standard ASP libraries <% url=”http://www.textmarketer.biz/gateway/?username=#&password=#&number=#&message=msg&orig=nameORnumber&option=xml” Set objXMLDoc = CreateObject(“Microsoft.XMLDOM”) objXMLDoc.async = False objXMLDoc.load(url) status = objXMLDoc.documentElement.selectSingleNode(“//response”).getAttribute(“status”) if status =...
  3. PHP 5 SMS Send Class implementing listeners on our SMS Gateway
    Class Name: SendSMSNotifier This class is designed around the FREE Text Marketer SMS API, you need to sign up here...
  4. SMS Gateway API – Specification
    This blog post has been superseded with our website documentation It is recommended that you use the  RESTful version of the API which has largely superseded this document...
  5. .NET Examples
    Example of a .NET Bulk SMS Gateway / API integration For more information regarding the bulk sending API click here....
  6. PHP and SMS
    PHP is the very popular web scripting language, to make things easy for the PHP programmer we have provided some...
  7. Is there such a thing as ‘quality’ in Bulk SMS?
    There are a vast number of different ‘gateways’ that bulk sms service providers can use to connect to the UK...
  8. Concatenated “Long Message” SMS feature now Live for the Bulk SMS system and the SMS Gateway
    You can now send text messages longer than 160 characters, in fact up to 612 characters which arrive as 1...
  9. How to integrate our SMS Gateway API into your systems
    Introduction Adding SMS as a communication method to a system is often very useful, for instance you don’t have issues...
  10. How RoughTrax increased sales by over 19% for next to nothing using Bulk SMS – could you?
    Further to our article, Top 5 Tips for increasing sales using Bulk SMS, one of our customers RoughTrax (a mail...

The service provided by Text Marketer Ltd must be used for solicited marketing only. All marketing messages sent must be delivered to devices/numbers that have positively opted into receiving SMS messages. To protect the privacy of recipients there is also an opt-out option included on every account, i.e “STOP”. We adhere fully to all best practices as set out by the Government’s Information Commissioner’s Office. For further information please follow this link. www.ico.org.uk/for_the_public/topic_specific_guides/marketing/texts

Copyright © 2012 Text Marketer Ltd | All Rights Reserved

Specialists in Mobile Marketing, Bulk SMS, SMS Marketing, SMS Gateway & Shortcode SMS