Code
Just pass to the method the parameters: Phone from the message is sent, Phone where the message should be delivered, and the text Message.
Set your own Twilio Account Sid and Twilio Auth Token.
uses
sgcHTTP;
procedure SendTwilioSMS(const aFrom, aTo, aMessage: string);
var
oHTTP: TsgcHTTP1Client;
oParams: TStringList;
vTwilio_Account_Sid, vTwilio_Auth_Token: string;
begin
oHTTP := TsgcHTTP1Client.Create(nil);
Try
oParams := TStringList.Create;
Try
vTwilio_Account_Sid := 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
vTwilio_Auth_Token := 'YYYYYYYYYYYYYYYYYYYYYYYYYYY';
oParams.Add(Format('Body=%s', [aMessage]));
oParams.Add(Format('From=%s', [aFrom]));
oParams.Add(Format('To=%s', [aTo]));
oHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
oHTTP.Request.BasicAuthentication := True;
oHTTP.Request.Username := vTwilio_Account_Sid;
oHTTP.Request.Password := vTwilio_Auth_Token;
Try
ShowMessage(oHTTP.Post('https://api.twilio.com/2010-04-01/Accounts/' + vTwilio_Account_Sid + '/Messages.json', oParams));
Except
On E: Exception do
ShowMessage(E.Message);
End;
Finally
FreeAndNil(oParams);
End;
Finally
FreeAndNil(oHTTP);
End;
end;