Jump to content
Ian Branch

SMS Sending - Still valid??

Recommended Posts

Hi Team,

A Customer has asked about sending SMS messages from their Delphi App.

I found the following code by Remy.

var
  lHTTP: TIdHTTP;
  lParamList: TStringList;
  lResult: String;
  IdSSL : TIdSSLIOHandlerSocketOpenSSL;
begin
  lParamList := TStringList.Create;
  try
    lParamList.Add('user=****');
    lParamList.Add('password=****' );
    lParamList.Add('message=Hello World');
    lParamList.Add('sender=TestAccount');
    lParamList.Add('mobile=+9195....');
    lParamList.Add('type=1'); // or 3

    lHTTP := TIdHTTP.Create(nil);
    try
      // note: if you are using an up-to-date version of Indy, 
      // assigning the IOHandler is optional:
      //
      // http://www.indyproject.org/sockets/blogs/ChangeLog/20141222.aspx
      //
      lHTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(lHTTP);
      try
        lResult := lHTTP.Post('https://www.bulksmsgateway.in/sendmessage.php', lParamList);
        // WriteLn(lResult);
        // Readln;
      except
        on E: Exception do begin
          //WriteLn('Error: ', e.Message);
        end;
      end;
    finally
      FreeAndNil(lHTTP);
    end;
  finally
    FreeAndNil(lParamList);
  end;
end;

Is it still valid?

 

Regards & TIA,

Ian

Share this post


Link to post

I have had a modicum of success with the above code.  It at least runs. 😉

I am getting the error..  "Error connecting with SSL". 😞

I have the latest ssleay & libeay dll files in the directory.

Share this post


Link to post
7 hours ago, Ian Branch said:

I am getting the error..  "Error connecting with SSL". 😞

Does the server require TLS 1.1+, by chance?  By default, TIdSSLIOHandlerSocketOpenSSL enables only TLS 1.0 (issue #181).  Have you tried enabling TLS 1.1 and/or TLS 1.2 in the TIdSSLIOHandlerSocketOpenSSL.SSLOptions.SSLVersions property?

Quote

I have the latest ssleay & libeay dll files in the directory.

Define "latest".  TIdSSLIOHandlerSocketOpenSSL requires OpenSSL 1.0.2 or earlier, it does not support OpenSSL 1.1+.  For that, you need to use this SSLIOHandler instead.

Edited by Remy Lebeau

Share this post


Link to post

Hi Remy,

Thank you.

I should have mentioned D11.1.1 with the GetIt Indy.

I am using the v 1.0.2u libraries.

I cannot see how/where to set the 'SSLOptions.SSLVersions := [sslvTLSv1_1, sslvTLSv1_2];'..

To me the logical place would be into IdSSL i.e. 'IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_1, sslvTLSv1_2];', however it doesn't appear to be being used anywhere.

 

Regards,

Ian

Share this post


Link to post
1 hour ago, Ian Branch said:

I cannot see how/where to set the 'SSLOptions.SSLVersions := [sslvTLSv1_1, sslvTLSv1_2];'..

To me the logical place would be into IdSSL i.e. 'IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_1, sslvTLSv1_2];', however it doesn't appear to be being used anywhere.

That is because your code is not using the IdSSL variable for anything.  You are creating the TIdSSLIOHandlerSocketOpenSSL instance and assigning it directly to the TIdHTTP.IOHandler property, thus leaving all of the IOHandler's sub-properties at their default values.

 

Assign the instance to the IdSSL variable first, and then you can customize its properties as needed, eg:

lHTTP := TIdHTTP.Create(nil);
try
  IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(lHTTP);
  IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
  // set other properties as needed...
  lHTTP.IOHandler := IdSSL;
  ...
finally
  lHTTP.Free;
end;

 

Edited by Remy Lebeau

Share this post


Link to post

Ahhh Ha!  Thanks Remy.

I figured it had to be something like that but I don't know enough about Indy and this type of thing.. :-(

All good now.

Appreciated.

 

Regards,

Ian

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×