Simba Code:
program GoogleVoiceSMSSender;
(*
SendSMS
~~~~~~~~~~
.. code-block:: pascal
function SendSMS(yourEmail, yourPassword, toNumber, theMessage: string): boolean;
Sends an SMS from a Google Voice account to a mobile number in the US.
yourEmail/yourPassword should have a Google Voice number set up @ voice.google.com
toNumber should be a 10 digit US number; no spaces nor special characters.
theMessage should be under 160 characters.
Please don't use this to spam people! Google takes abuse seriously.
.. note::
Author: Harry and Sex
Last Modified: 4 November 2014
Example:
.. code-block:: pascal
if SendSMS('FakeGoogleLogin@gmail.com', 'mypassword', '5551231234', 'This Simba SMS sending is really cool!') then
WriteLn('Woohoo!');
*)
function SendSMS(yourEmail, yourPassword, toNumber, theMessage: string): boolean;
var
cl, i, redir: integer;
verifyStatus, s, loc, _rnr_se: string;
PostVars: TStringArray;
begin
try
cl := InitializeHTTPClient(True);
SetHTTPUserAgent(cl, 'SimbaVoice/0.2');
verifyStatus := '';
if (length(yourEmail) < 1) or (length(yourPassword) < 1) then
verifyStatus := 'up';
if (length(toNumber) <> 10) then
verifyStatus := 'number';
if (length(theMessage) > 160) then
verifyStatus := 'message';
case verifyStatus of
'up': WriteLn('Email or Password is invalid!');
'number': WriteLn('Number is invalid! Number must be 10 digits, no spaces or symbols.');
'message':
begin
WriteLn('WARNING: Your message is long (length: '+toStr(length(theMessage))+' characters)!');
WriteLn(' Your message should be under 160 characters, but it will most likely still go through.');
verifyStatus = '';
end;
end;
if (verifyStatus <> '') then
Exit;
WriteLn('Logging into Google Voice.'); // Load login page for GALX etc
s := GetHTTPPage(cl, 'https://accounts.google.com/ServiceLogin?service=grandcentral&passive=1209600&continue=https://www.google.com/voice&followup=https://www.google.com/voice<mpl=open');
if (length(s) < 10) then
begin
WriteLn('You don''t have the SSL libs for Simba, or https://accounts.google.com/ is blocked by your firewall.');
WriteLn('You must place libeay32.dll and libssl32.dll in the same folder as your Simba.exe!');
Exit;
end;
PostVars := ['Email', yourEmail,
'GALX', between(' value="', '">', s),
'Passwd', yourPassword,
'continue', 'https://www.google.com/voice',
'followup', 'https://www.google.com/voice',
'service', 'grandcentral',
'signIn', 'Sign in'];
for i := 0 to high(PostVars) do
begin
AddPostVariable(cl, PostVars[i], PostVars[i + 1]);
inc(i);
end;
s := PostHTTPPageEx(cl, 'https://accounts.google.com/ServiceLoginAuth');
ClearPostData(cl);
if (pos('LoginDoneHtml', s) <> 0) then
WriteLn('Login successful!')
else begin
WriteLn('Login failed. Check your username/password and ensure your Google account is validated.');
Exit;
end;
WriteLn('Loading inbox, please be patient...');
redir := 0;
repeat // follow Google's insane number of redirects.
loc := between('Location: ', #13#10, GetRawHeaders(cl));
writeln(loc);
if loc <> '' then
s := GetHTTPPage(cl, loc)
else
break;
DebugLn('Following link to '+ loc);
if (redir > 9) then
begin
WriteLn('Took over 9 redirects to get to Google Voice. Something is wrong!');
Exit;
end;
inc(redir);
until(loc = '');
_rnr_se := between('<input name="_rnr_se" type="hidden" value="','"/>',s); // Some anti-CSRF stuff Google has.
if (_rnr_se = '') then
begin
WriteLn('The CSRF code was not found properly!');
WriteLn('Ensure your Google Voice account works, and that you have a US-based IP address.'); // country-specific Google domains break this script for some reason, t.ex google.se
Exit;
end
else
DebugLn('CSRF: '+_rnr_se);
WriteLn('Sending SMS now...!');
AddPostVariable(cl, 'phoneNumber', '+1'+toNumber);
AddPostVariable(cl, 'text', theMessage);
AddPostVariable(cl, '_rnr_se', _rnr_se);
s := PostHTTPPageEx(cl,'https://www.google.com/voice/sms/send/');
ClearPostData(cl);
if (Pos('Your client has issued a malformed or illegal request',s) <> 0) then
begin
WriteLn('You got a HTTP-400 error from Google. This means you sent invalid cookies. This probably means your Simba is out of date.');
Exit;
end;
case s of // return codes. There is no published list, and these may be inaccurate.
'{"ok":true,"data":{"code":0}}':
begin
WriteLn('SMS sent okay!');
Result := True;
end;
'{"ok":false,"data":{"code":2046}}':
WriteLn('Error 2046: you do not have a Google Voice number.');
'{"ok":false,"data":{"code":67}}':
WriteLn('Error 67: invalid destination (only US numbers supported)');
else
WriteLn('We did not get a proper send code. Result: '+s);
end;
finally
FreeHTTPClient(cl);
end;
end;
begin
ClearDebug;
if SendSMS('usename@gmail.com','password','5555555555','Simba is cool!') then
writeln('Yay!');
end.