- #!/usr/bin/perl
- # Mail to SMS gateway script, version 1.0
- # By Andy Hawkins (andy@gently.demon.co.uk)
- # Set this to be the path to your mail program
- $MAILER="/usr/lib/sendmail -t";
- # Set this to the maximum number of tries for a message
- $retries=5;
- $foundblank=0;
- $number="";
- headerloop: while(<>)
- {
- chomp;
- if (/^From:s(S+)/)
- {
- $fromaddr=$1;
- }
- if (/^Subject:s(S+)/)
- {
- $number=$1;
- }
- if (/^$/)
- {
- $foundblank=1;
- last headerloop;
- }
- }
- $msg="";
- messageloop: while (<>)
- {
- chomp;
- last messageloop if /^quit$/ or /^end$/;
- if ($msg)
- {
- $msg=$msg." ".$_;
- }
- else
- {
- $msg=$_;
- }
- }
- print "Message is to $numbern";
- print "Message is ($msg)n";
- $success=0;
- $longmsg=0;
- $badservice=0;
- $badnumber=0;
- if ($number)
- {
- sendloop: while ($retries)
- {
- $retcode=system ("/usr/bin/sms_client $number "$msg"")/256;
- # $retcode=system ("exitstat.pl $number "$msg"")/256;
- if ($retcode==0)
- {
- $success=1;
- last sendloop;
- }
- else
- {
- print "Failed with retcode $retcoden";
- if ($retcode==1)
- {
- $longmsg=1;
- last sendloop;
- }
- if ($retcode==3)
- {
- $badservice=1;
- last sendloop;
- }
- if ($retcode==4)
- {
- $badnumber=1;
- last sendloop;
- }
- sleep 5;
- $retries--;
- }
- }
- }
- open MAIL,"|$MAILER";
- #print MAIL "From: $MAIL_FROMn";
- print MAIL "To: $fromaddrn";
- if ($success)
- {
- print MAIL "Subject: SMS to $number sent successfullyn";
- print MAIL "n";
- print MAIL "Your SMS to $number was sent successfullyn";
- }
- else
- {
- print MAIL "Subject: SMS to $number failedn";
- print MAIL "n";
- print MAIL "Your SMS to $number failedn";
- unless ($number)
- {
- print MAIL "No number found in subject headern";
- }
- if ($longmsg)
- {
- print MAIL "Your message was too longn";
- }
- if ($badservice)
- {
- print MAIL "An invalid service was specifiedn";
- }
- if ($badnumber)
- {
- print MAIL "The number $number could not be expandedn";
- }
- }
- close MAIL;