Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Sending SMS msgs to AT&T phone / Coping with forms that want cookies

by dws (Chancellor)
on Jun 28, 2002 at 16:50 UTC ( [id://178065] : CUFP . print w/replies, xml ) Need Help??

A simple, anti-bot defensive measure that some sites have put together requires that a POST request be accompanied by a session cookie presented when the form was retrieved. AT&T Message Center uses this technique. The following fragment demonstrates how to work through this barrier and send SMS message to AT&T subscriers.

Please use this responsibly.

# This code fragment demonstrates how to send an SMS text message to # an AT&T wireless subscriber who has an SMS-enabled cell phone. This # can be used to send an SMS message to yourself when certain events # happen on your server/website. # # At present, AT&T message center presents a browser with a cookie # when the SMS message form is retrieved, and won't send an SMS # message unless the cookie is presented along with the POST to # their CGI. Below we use HTTP::Cookies to set up a cookie jar to # hold the cookie, and present it along with the post. # # There are a number of SMS packages on CPAN, and they're worth # exploring. At the time I put this together, I didn't find anything # there that coped with the cookie requirement. # # Please use this responsibly. # # 28 June 2002 Dave W. Smith <> use HTTP::Request::Common qw(GET POST); use HTTP::Cookies; use LWP::UserAgent; my $messageCenter = ""; my $pagersend = "$messageCenter/pagersend.cgi"; # ---- change these as appropriate ---- my $phoneNumber = die "phone number here"; my $msgFrom = "me"; # name or phone number my $msgSubject = "Test"; # optional subject my $msgBody = "Hello World!"; # from + subject + body <= 140 chars # ------------------------------------- # Set up a UserAgent with a cookie jar my $ua = new LWP::UserAgent(); my $cookies = new HTTP::Cookies(); $ua->cookie_jar($cookies); # Get the pager request form. This gets the cookie we'll need # later to send the message. my $req = GET "$messageCenter/"; my $response = $ua->request($req); if ( ! $response->is_success() ) { die "Couldn't get form from message center"; } # Send the SMS message $req = POST $pagersend, [ pin => $phoneNumber, from => $msgFrom, subject => $msgSubject, message => $msgBody ]; $response = $ua->request($req); if ( ! $response->is_success() ) { die "Can't submit page request"; } my $content = $response->as_string(); if ( $content !~ m/your message has been submitted/i ) { die "Server didn't like page request\n"; } print "Sent\n";

Replies are listed 'Best First'.
Re: Sending SMS msgs to AT&T phone / Coping with forms that want cookies
by Anonymous Monk on Jul 17, 2002 at 16:21 UTC
    I did something simalur to this but added an option in SendMail to redirect an email address to the script. This way I could have email paging. Just Ideas!!!!!!!!!!!
    /etc/aliases pagebrad: "| /usr/bin/" --------------------------------------- /usr/bin/ while (<STDIN>) {$org_msg .= $_}; $org_msg =~ /([Ss]ubject: )(.*)/; $msg = $2 if $2; $org_msg =~ /([Ff]rom: )(.*)/; $from_field = $2 if $2; $URL = ''; use HTTP::Request::Common qw(POST); use LWP::UserAgent; $ua = new LWP::UserAgent; my $req = POST $URL, [ PIN => $pgr_num, From => $from_field, Subject => $subj, Message => $msg, tr => "PinSend", page_name => "Phnximg" ];
      hiiiiiiiiiiii did u receive my msg? take care byeeeeeeeeeeee