I have something like this setup.


I send email to a certine user (I created sms user on the kannel box).

Then via cronjob, I use perl to read the email, and send it to the http.



Here is the perl script (found it somewhere on the web, modified it a bit) :

Please change the yellow to suite your needs:







#!/usr/local/bin/perl -w

use Net::POP3;

use strict;

use LWP::UserAgent;





# Connect to pop3 server

my $pop3 = Net::POP3->new("Kannel_server") || die "Error : Couldn't log+on to 
server";



# Login to pop3 server

my $Num_Message = $pop3->login("mailbox_username", "mailbox_passwd");



my $Messages = $pop3->list();

my ($MsgDel,$MsgNo);

my ($MsgId, $MsgDate, $MsgFrom, $MsgTo, $MsgCc, $MsgSub);

my ($MsgAttach, $MsgSize, $MsgHeader, $MsgHeadFlg, $MsgBody);



foreach $MsgNo (keys %$Messages)

{

  my $MsgContent = $pop3->get($MsgNo);

  my $count = 0;

  $MsgHeadFlg = 0;

  $MsgBody = "";



  $MsgSize = $pop3->list($MsgNo);



  # Process message data

  while()

  {



    # Exit if last line of mail

    if ($count >= scalar(@$MsgContent))

    {

      last;

    }



    # Check if end of mail header

    if (@$MsgContent[$count] =~ /^\n/)

    {

      $MsgHeadFlg = 1;

    }



    # Proceed if message header not processed

    if (not $MsgHeadFlg)

    {



      # Split the line

      my @LineContent = split /: /, @$MsgContent[$count];



      # Check Header Info

      SWITCH:

      {

        # Get message date

        $LineContent[0] =~ /Date/i && do

                                       {

                                         $MsgDate = $LineContent[1];

                                         last SWITCH;

                                       };



        # Get message id

        $LineContent[0] =~ /Message-ID/i && do

                                       {

                                         $MsgId = $LineContent[1];

                                         last SWITCH;

                                       };



        # Get message from

        $LineContent[0] =~ /From/i && do

                                      {

                                        $MsgFrom = $LineContent[1];

                                        last SWITCH;

                                      };



        # Get message to

        $LineContent[0] =~ /To/i && do

                                      {

                                        $MsgTo = $LineContent[1];

                                        last SWITCH;

                                      };



        # Get message cc

        $LineContent[0] =~ /Cc/i && do

                                      {

                                        $MsgCc = $LineContent[1];

                                        last SWITCH;

                                      };





        # Get message subject

        $LineContent[0] =~ /Subject/i && do

                                      {

                                        $MsgSub = $LineContent[1];

                                        last SWITCH;

                                      };

      }

    }

    else

    {

      # Process message body

      $MsgBody .= @$MsgContent[$count];

    }

    $count++;

  }



my $ua = new LWP::UserAgent;

$ua->timeout(120);



my $result = `ps | grep  -v grep|grep smsbox |awk \'{print \$1}\'`;



   if ( $result  > 0  )

    {

        my 
$url="http://kannel_server:kannel_port/cgi-bin/sendsms?username=xxx&password=xxx&to=$MsgSub&text=$MsgBody";;

        my $request = new HTTP::Request('GET', $url);

        my $response = $ua->request($request);

        my $content = $response->content();

        $MsgDel = $pop3->delete($MsgNo)

    }

}



# Disconnect from pop3 server

$pop3->quit();



-----Original Message-----
From: Niels Przybilla [mailto:[EMAIL PROTECTED]
Sent: Monday, June 02, 2008 8:25 AM
To: [email protected]
Subject: mail2sms script



Hi,



is there any current development for a script that parses mails and

sends them with kannel via sms ?



Thanks and best regards



Niels


Reply via email to