Hi, buddies:

I use sendmail's smrsh done this ;)

my system is Redhat linux:

*smrsh configuration*

cd /etc/smrsh/

sudo ln -s /home/feed/mail2sms.pl

*virusertable configuration*

@feed.foobar.com feed

@hostname feed

#cd /etc/mail

#makemap hash virusertable.db < virusertable 使虚拟用户生效 **目录为 /etc/mail

*aliases configuration* (/etc/aliases or /etc/mail/aliases)

feed
"|/home/feed/mail2sms.pl"
*reload aliases*

#newaliases

attachment is my mail2sms script, code is a little old,but still work now ;) have fun~

Yan Lu

Stipe Tolj 写道:
Niels Przybilla schrieb:
Hi,

is there any current development for a script that parses mails and sends them with kannel via sms ?

none that is in the contri/ directory AFAIK.

There are different approaches IMO to handle a mail2sms bridge for Kannel:

The simple way:
- use procmail, and pass the corresponding sections to a shell or php script passing the fields to the sendsms HTTP interface.

The state-of-the-art way:
- implement a module for your favorite MTA, i.e. exim, to handle the mail and passing it via a persistent socket connection to the bearerbox. This is not easy, since exim (like apache) is a pre-forked model architecture, where each incoming mail is hand over to a spawned exim process and after the processing is done, the process is stopped. So it's tricky to handle the "persistence connection" towards bearerbox.

Here again 2 options:
- make the exim module call the sendsms HTTP interface of smsbox, i.e. using cURL calls in the exim module. - use a stub "smsbox connection daemon", let's call it udpbox, which connects to bearerbox and listens on the other side for UDP datagrams. Each exim process that handles the inbound email would then issue a simple (and fast acting) UDP datagram to the udpbox ensuring the information is passed fast the line towards bearerbox.

Stipe ;)

-------------------------------------------------------------------
Kölner Landstrasse 419
40589 Düsseldorf, NRW, Germany

tolj.org system architecture Kannel Software Foundation (KSF)
http://www.tolj.org/ http://www.kannel.org/

mailto:st_{at}_tolj.org mailto:stolj_{at}_kannel.org
-------------------------------------------------------------------




#!/home/y/bin/perl -w

##   functions to use
use strict;
use DBI;
use LWP::Simple;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
my (
    $from, $subject, $to,   $oto,    $cc,      $content,
    $user, $flag,    $temp, $msg_id, $logfile, $sendtime
);
my ( $hour, $min, $sec );
my ( $yy, $mm, $dd ) = ( localtime(time) )[ 5, 4, 3 ];
my @temp;
my @match;
my ( $receiver, @receivers );
my ( $dbh, $dbuser, $dbpass ) = ( "", "root", "" );

###### CREATE DATABASE CONNECTION ######
$dbh = DBI->connect( "DBI:mysql:database=smsdate;host=localhost",
    "$dbuser", "$dbpass" )
  || print "$!\n";
#################################
$sendtime = `date`;
chomp $sendtime;
( $hour, $min, $sec ) = ( localtime(time) )[ 2, 1, 0 ];
$msg_id = sprintf( "12%02d%02d%02d", $hour, $min, $sec );

# Getting infomations from mail
while (<STDIN>) {
    chomp;
	undef @match;
    #system("echo $_ >> /tmp/result.txt");#get the mail raw content
    if (/^[Ff]rom/) {
        $from = $_;
        $from =~ s/^from (.*)/$1/gis;
        @temp = split( / +/, $from );
        $from = $temp[1];    # second column is sender
        $from =~ s/\"//gis;
    }

    if (/^[Ss]ubject:/) {
        $subject = $_;
        $subject =~ s/^Subject: //gis;
        $subject =~ s/\'//gis;

    }
## grap all [EMAIL PROTECTED] address
    #		 if (/^To/) {
    $to = $to . $_;

    #	$to =~ s/^To: //gis;
    #	        }
    if (/^Cc/) {
        $cc = $_;
        $cc =~ s/^Cc: //gis;
    }
}

if ($to) {
    while ( $to =~ /page-([EMAIL PROTECTED])@/g ) {
		@match = grep (/^$1$/, @receivers);
		if([EMAIL PROTECTED]){
			push @receivers, $1;
		}
    }
}

if ($cc) {
    while ( $cc =~ /page-([EMAIL PROTECTED])@/g ) {
		@match = grep (/^$1$/, @receivers);
		if([EMAIL PROTECTED]){	
			push @receivers, $1;
		}
    }
}

#foreach my $receiver (@receivers){
#	system("echo  $receiver >> /tmp/ya.txt");
#}

## call checkpolicy to update the policy table in the database
#system("/home/feed/checkpolicy.pl");

## get the right uid or gid or oncall_group id
for my $temp_user (@receivers) {
    my @idresult =
      &findgroup_sub($temp_user);  #checkup whether the $temp_user is a group_id
    my %result;
    my $temp_uid;
    if (@idresult) {
        my $sn =
          &findschedule_sub($temp_user)
          ;                        #get the sn of the oncall-group from schedule
        if ($sn) {
            my @uid =
              &findoncall_sub( $sn, $temp_user )
              ;                    #get the whole user whose sn is the right sn
            foreach $temp_uid (@uid) {
                $result{$temp_uid} =
                  &finduser_sub($temp_uid);    #get the phone-number of the user
            }
            &outputuser_sub(%result);
        }
        else {

       # the group-id is not a oncall-group ,get the whole members' phone-number
            foreach $temp_uid (@idresult) {
                $result{$temp_uid} = &finduser_sub($temp_uid);
            }
            &outputuser_sub(%result);
        }
    }
    else {

        # the id is a user-id only, get the phone-number
        $result{$temp_user} = &finduser_sub($temp_user);
        if (%result) {
            &outputuser_sub(%result);
        }
    }
}

$dbh->disconnect();

##
## Subroutines
##

#############################
#####    DATABASE FUNCTIONS     ######
#############################

########## get the whole uid of the group-id
sub findgroup_sub {
    my ($gid) = @_;
    my $sth = $dbh->prepare("SELECT * FROM groups where gid='$gid'");
    $sth->execute() || die "Can't execute the sql:$!";
    my @temp_list;
    my $count = 0;
    while ( my $ref = $sth->fetchrow_hashref() ) {
        $temp_list[$count] = $ref->{'uid'};
        $count++;
    }
    $sth->finish();
    return @temp_list;
}

######### get the oncall-group's sn
sub findschedule_sub {
    my ($gid) = @_;
    my $sth = $dbh->prepare("SELECT * FROM schedule where gid='$gid'");
    $sth->execute();
    my $temp_id;
    while ( my $ref = $sth->fetchrow_hashref() ) {
        $temp_id = $ref->{'sn'};
    }
    if ( $temp_id eq "" ) {
        return 0;
    }
    $sth = $dbh->prepare("SELECT max(sn) as sn FROM oncall where gid='$gid'");
    $sth->execute();
    my $max_sn;
    while ( my $ref = $sth->fetchrow_hashref() ) {
        $max_sn = $ref->{'sn'};
    }
    $temp_id = ( $temp_id == 1 ) ? ( $temp_id = $max_sn ) : ( $temp_id - 1 );
    $sth->finish();
    return $temp_id;
}

############ get the oncall's member oncall.sn == schedule.sn
sub findoncall_sub {
    my ( $gsn, $gid ) = @_;
    my $sth =
      $dbh->prepare("SELECT * FROM oncall where gid='$gid' and sn='$gsn'");
    $sth->execute();
    my @temp_id;
    my $count = 0;
    while ( my $ref = $sth->fetchrow_hashref() ) {
        $temp_id[$count] = $ref->{'uid'};
        $count++;
    }
    $sth->finish();
    return @temp_id;
}

########## get the user' phonenumber, this number is the right number willbe send sms
sub finduser_sub {
    my ($uid) = @_;
    my $sth = $dbh->prepare("SELECT * FROM users where uid='$uid' ");
    $sth->execute();
    my $temp_phone;
    my $ref = $sth->fetchrow_hashref();
    $temp_phone = $ref->{'phone'};
    $sth->finish();
    return $temp_phone;
}

#############################
####### SEND SMS FUNCTION #######
#############################
sub outputuser_sub {
    my (%result) = @_;
    while ( my ( $user, $usernum ) = each(%result) ) {
        if ( $user && $usernum ) {

            #print $user.":".$usernum."\n";
            system(
"/bin/echo '$sendtime,$user,$usernum,$subject,$from' >> /home/feed/log.txt"
            );
            my $smscontent = $subject . ' from ' . $from;
            my $result     = getprint
"http://foobar.com:13013/cgi-bin/sendsms?username=tester&password=foobar&to=$usernum&text=$smscontent";;
            system("/bin/echo $result >> /home/feed/log.txt");
        }
    }
}
#### null gateway
sub outputuser_sub_null {
    my (%result) = @_;
    system( "/bin/echo " . %result . " >> /home/feed/null.txt" );
}


## End of program

Reply via email to