Link to home
Start Free TrialLog in
Avatar of Sathish R
Sathish R

asked on

How to send sms using Delphi code

I have used 3 set of codes(where I used Indy10.6.2 component), which doesn't show any errors, but i can't able to send SMS through the code. Please help me to send me the Sms through Delphi code

The code which I used is...

const
  URL = 'https://api.bulksmsgateway.in/send/?username=****&hash=****&sender=TXTLCL&numbers=9198........&message=HISUNDAR';
  //URL = 'https://api.textlocal.in/send/?username=*****&hash=******&sender=TXTLCL&numbers=9198...&message=HISUNDAR';
  ResponseSize = 1024;
var
  hSession, hURL: HInternet;
  Request: String;
  ResponseLength: Cardinal;
begin
  hSession := InternetOpen('TEST', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  try
    Request := Format(URL,[Username,Password,Sender,Numbers,HttpEncode(Message1)]);
    hURL := InternetOpenURL(hSession, PChar(Request), nil, 0,0,0);
    try
      SetLength(Result, ResponseSize);
      InternetReadFile(hURL, PChar(Result), ResponseSize, ResponseLength);
      SetLength(Result, ResponseLength);
    finally
      InternetCloseHandle(hURL)
    end;
    showmessage(result);
  finally
    InternetCloseHandle(hSession)
  end





var
http : TIdHTTP;
IdSSL : TIdSSLIOHandlerSocketOpenSSL;
begin
 http := TIdHTTP.Create(nil);
 IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
 try
  Http.ReadTimeout := 30000;
  Http.IOHandler := IdSSL;
  IdSSL.SSLOptions.Method := sslvTLSv1;
  Http.Request.BasicAuthentication := True;
 // IdSSL.SSLOptions.Method := sslvTLSv1;
  //IdSSL.SSLOptions.Method := sslvTLSv1;
 // http.Get('https://www.smsgatewayhub.com/api/mt/SendSMS?APIKey=B215dPone0yVIJU2QDH&senderid=TESTIN&channel=2&DCS=0&flashsms=0&number=9195.....&text=test message&route=1');
   http.Get('http://login.bulksmsgateway.in/sendmessage.php?user=****&password=****&mobile=95661....&message=Good Morning&sender=PRAPUS&type=3 ');
 finally
  http.Free;
 end;





  var
  lHTTP: TIdHTTP;
  lParamList: TStringList;
  lResult: String;
  IdSSL : TIdSSLIOHandlerSocketOpenSSL;
begin
  lParamList := TStringList.Create;
  lParamList.Add('username=****');                                              
  lParamList.Add('password=****');                                        
  lParamList.Add('msgtext=Hello World');                                            
  lParamList.Add('originator=TestAccount');                                         
  lParamList.Add('phone=+9195....');                                                
                                                                                    
  lParamList.Add('showDLR=0');                                                            
                                                                                          
                                                                                          
  lParamList.Add('charset=0');                                                            
  lParamList.Add('msgtype=');                                                             
  lParamList.Add('provider=bulksmsgateway.in');                                 

  lHTTP := TIdHTTP.Create(nil);                                                           
  try
   
    lResult := lHTTP.Post('http://login.bulksmsgateway.in/sendmessage.php?', lParamList);       
    //WriteLn(lResult);                                                               
   // Readln;
  finally
    FreeAndNil(lHTTP);                                                        
    FreeAndNil(lParamList);
  end;
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Where you call https site - you should implement TIdSSLIOHandlerSocketOpenSSL, for common http - you don't need it.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.