Michael Silverman documenting innovation at work

16Nov/110

Sending Text Messages with Perl and Google Voice

It is much easier to send a SMS text message with Perl than you might think. You wouldn't know unless you searched but there is a module out there called Google::Voice. The module allows you to use your Google Voice account from Perl. It's not installed by default with Perl so you will need to install it. The easiest way to do this would be to type

perl -MCPAN -e "install Google::Voice"

This will install Google::Voice and all of it's dependencies.

Now to write a text message is so simple!

use Google::Voice;

#Google login info
my $username    = 'myuser@host.com';
my $password    = "mypasword";

#text message info
my $send_number = "14443216789";
my $send_text   = "I'm a text message!";

#Do Not Edit Below Here!

#create Google::Voice object and login
my $gv_obj = Google::Voice->new->login($username, $password);

#send the text!
$gv_obj->send_sms($send_number => $send_text);

Now say you want to send a text message by calling the script from outside Perl.